OSSA_Workshop 07_Shell Scripting
OSSA_Workshop 07_Shell Scripting
Workshop sheet 05
Year 02 Semester 01
Department of Information Technology, Faculty of Computing
2) In UNIX environment, some of the processes are sent to background, to run the as background
processes.
a) What is the importance of this in UNIX operating system?
ps command – displays information about all processes running on the system, including
background processes as well.
jobs: The jobs command lists the status of all background processes running in the current
shell session. It displays the job ID, status, and command for each background process.
fg % <PID>
You can bring a background process to the foreground by specifying its job ID. The job ID
can be found using the jobs command. Then, use the fg command followed by the job ID.
the error message "Hello: no such a file or directory" occurs because the system is
trying to execute a command named hello, but it cannot find an executable file with
that name in any of the directories listed in the system's PATH environment variable.
To execute a script using only by it’s name it should be available in the path variable.
/home/sunit/demo is not in the path variable.
b) By using your knowledge about environment variables, explain how to avoid the above error.
The PATH environment variable tells the shell where to look for executable files. By
default, the current directory (.) is not included in PATH for security reasons.
echo $PATH
PATH=$PATH:/home/sunil/demo
echo $PATH #now the path is being added. Then execute and see no such error
5) Explain how “grep“ and “cut” commands can be used to retrieve the preferred shell of user “sunil”.
(hint: preferred shell is 7th field of a passwd file entry)
-------------------------------------------------------------------------------------------------------
Grep – used to search pattern within the file
Cut – used to extract specific sections of each line form a file
a
Jan
b C1own Gi1d
| = pipe operator: take ouput of the command on its LHS and pass it as input to the
command on its RHs
Tr – translate characters
R to l
B to g
$ cat users
Andrew Roberts
Smith Samson Adams smith
Adams smith
Paul Alert
Smith Martinet
However, note that grep is case-sensitive by default, so it will only match "smith" and not "Smith".
sort -: This part of the command is intended to sort the output from grep.