≡ Menu

bash shell

How do I find out what shell I’m using?

Asked by Chetan Joshi

Q. What is the best way to find out what shell I'm using. echo $SHELL is not so reliable. Please let me know any tiny command or trick.

A. Chetan, echo $SHELL should work. But here is old good UNIX trick. Use the command ps with -p {pid} option, which selects the processes whose process ID numbers appear in pid. Use following command to find out what shell you are in:

ps -p $$

So what is $ argument passed to -p option? Remember $ returns the PID (process identification number) of the current process, and the current process is your shell. So running a ps on that number displays a process status listing of your shell. In that listing you will find the name of your shell (look for CMD column) .

$ ps -p $$

  PID TTY          TIME CMD
6453 pts/0    00:00:00 csh

From my Linux box:
$ ps -p $$

  PID TTY          TIME CMD
5866 pts/0    00:00:00 bash

You can store your shell name in a variable as follows :
MYSHELL=`ps -hp $$|awk '{echo $5}'`

Please note those are backquotes, not apostrophes

Or better try out following if you have a bash shell:

MYSHELL=$(ps -hp $$|awk '{echo $5}')

BASH Shell: HowTo Create Empty Temporary Files Quickly

Use any one of the following command to create temporary empty file names. The first command is special as it use the redirection operator >, the redirection refers to the standard output. So you are creating a new file or destroying existing file:
[click to continue…]

FreeBSD: Customize Home, Del, Insert keys for BASH shell

By default when you use FreeBSD's BASH shell and if you hit Home, Del, Insert keys all of them just prints ~ (some garbage is printed ). To get rid of this problem, edit /etc/profile file and define key binding.

1) Open your bash global profile file:
# vi /etc/profile

2) Add following line to it:
export INPUTRC=/usr/local/etc/inputrc

3) Close and save the file

4) Open the file /usr/local/etc/inputrc and define / modify key binding:
# vi /usr/local/etc/inputrc

5) Append following config data:

set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word

6) Close and save the file

7) Now logout and login back again to test your new key settings.