Here a short blog post… if you work in several companies or with different accounts, it’s useful to know, which shell you’re currently using (not the default shell from /etc/passwd). Of course, you can simply change the shell and choose your favorite one, but if you just want to know the actual shell, you can run one of the following two commands.
The special variable $0 contains the name of the running “script” itself. The brackets {} are optional, but I recommend to always set them in shell scripts.
echoecho ${0} # recommendation in shell scripts. echo $0 # short version.# recommendation in shell scripts. echo $0 # short version.
bash ksh sh">bash ksh sh
In the special variable $$ is the process id of the parent process of your session saved. And with the command ps -p informations about the process is printed out. Here again, the brackets are optional.
ps -p ${$} # recommendation in shell scripts. ps -p $$ # short version.
Here are three sample outputs:
PID TTY TIME CMD 15912 pts/2 00:00:00 sh 15886 pts/3 00:00:00 ksh 15574 pts/1 00:00:00 bash
On this page or the bash man page are more special variables listed, which can be useful for scripting.
Stay tuned, soon we’re launching a scripting guideline series on this blog and there, we’ll describe the brackets in detail….
6 Comments