$SHELL is the environment variable that holds your preferred shell, not the currently running shell. It's initialised by
login or any other application that logs you in based on the shell field in your user entry in the
passwd database (your login shell).
That variable is used to tell applications like
vim... what shell they should start for you when they start a shell. You typically change it when you want to use another shell than the one set for you in the
To get a path of the current shell interpreter, on Linux, and with Bourne or csh like shells, you can do:
set pid %self
csh/tcsh set the
$shell variable to the path of the shell.
In Bourne-like shells,
$0 will contain the first argument that the shell received (
argv) which by convention is the name of the command being invoked (though
login applications, again by convention make the first character a
- to tell the shell it's a login shell and should for instance source the
.login file containing your login session customisations) when not called to interpret a script or when called with
shell -c '...' without extra arguments.
$ bash -c 'echo "$0"'
$ /bin/bash -c 'echo "$0"'
It's my shell that calls
/bin/bash in both cases, but in the first case with
bash as its first argument, and in the second case with
/bin/bash. Several shells allow passing arbitrary strings instead like:
$ (exec -a whatever bash -c 'echo "$0"')