Difference between "echo $SHELL" and "which bash"
Your system probably has bash
installed in multiple locations, whether as different versions of bash
or just symbolic links.
which
is not really a useful command for most purposes - it's not really portable or very usable in scripts. In general, type
is better. The idea behind which
is to do a PATH
search for the command you give it as an argument.
$SHELL
does not necessarily reflect the currently running shell. Instead, $SHELL
is the user's preferred shell, which is typically the one set in /etc/passwd
. If you start a different shell after logging in, you can not necessarily expect $SHELL
to match the current shell anymore.
As you can see, $SHELL
and which
are completely unrelated. Neither of these will tell you what shell you are actually running.
A side note: Unfortunately, matching the shell you are currently running to a location in the filesystem is harder than one might think. This is because binaries are loaded into memory in order to run, and in most systems the copy in memory will continue to run fine even after you delete the original from disk (the kernel may keep the disk copy around in "limbo" until it is really no longer needed). I don't think there is any portable way to go about this - you'd have to resort to platform specific methods. For example, on Linux, examining the link /proc/$$/exe
should give you a decent idea of what file is running (where $$
is the process ID of your running shell). Unfortunately I am not familiar with Solaris, so I can't help you there.
The other answers are good, but I like to give a demonstration.
% echo $SHELL
/bin/zsh
% which bash
/bin/bash
- The first command tells me which shell will be executed by
login
when you log in. In my case,/bin/zsh
. - The second command tells me the first occurrence in my
$PATH
thebash
command can be found.
One does not imply the second, nor vice versa.
I'm not going to restate other people's answers but in addition to that I want to point out some things.
- The default shell on Solaris is
/bin/bash
- On Solaris
/bin
is a symlink to./usr/bin
- The default
$PATH
on Solaris is/usr/bin:/bin
That's why you're seeing this behavior.