$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 xterm, 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 passwd database.
To get a path of the current shell interpreter, on Linux, and with Bourne or csh like shells, you can do:
readlink "/proc/$$/exe"
The rc equivalent:
readlink /proc/$pid/exe
The fish equivalent:
set pid %self
readlink /proc/$pid/exe
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[0]) 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 .profile or .login file containing your login session customisations) when not called to interpret a script or when called with shell -c '...' without extra arguments.
In:
$ bash -c 'echo "$0"'
bash
$ /bin/bash -c 'echo "$0"'
/bin/bash
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"')
whatever
In ksh/bash/zsh/yash.
readlink /proc/(echo %self)/exeinstead. – bot47 Dec 14 '16 at 16:23stracedfish -c "readlink /proc/1/exe"andfish -c "readlink /proc/(echo %self)/exe". Both only issue just one clone-syscall, neither forks nor execs. But I'm tired, maybe I'm missing something. – bot47 Dec 15 '16 at 19:29fishoriginal author aware of those ksh93 optimisations just yesterday). Thanks for making me aware of it. – Stéphane Chazelas Dec 15 '16 at 20:42