Write a shell script that outputs the name of the shell executing it.
What will be an ideal response?
There are many ways to solve this problem. The following solutions are all
basically the same. These scripts take advantage of the PPID shell variable,
which holds the PID number of the shell that is the parent of the process
using the variable. They also use the fact that echo changes multiple sequen-
tial SPACEs to a single SPACE. The cut utility interprets multiple sequential SPACEs
as multiple delimiters, so the script does not work properly without echo.
$ cat a
pid=$PPID
line=$(ps | grep $pid)
echo $line | cut --delimiter=" " --fields=4
$ cat a2
pid=$PPID
echo $(ps | grep $pid) | cut --delimiter=" " --fields=4
$ cat a3
echo $(ps | grep $PPID) | cut --delimiter=" " --fields=4
The easy solution is to give the following command:
$ echo $0
The $0 is the first command-line token, which is usually the name of the
script or program that is running (page 476). In some cases, such as when
you call the script with a relative or absolute pathname, this outcome might
not be exactly what you want.
You might also like to view...
The first widely used graphical web browser was developed at:
a. CERN b. NCSA c. W3C d. ARPA
Unix determines if a filename refers to a device by
A. seeing if the file is in the /dev directory B. checking the file type stored in the inode of the file