Read MadeInGermany answer, aliases are simply not supported by the legacy Bourne shell which predates functions. There is no point trying to define and execute an alias under /sbin/sh or /bin/sh when running Solaris 10 and older.
In any case, to see what an alias contains, echo is the wrong command, as RudyC already posted, you simply use the alias builtin too (when supported by the shell).
Finally, "echo $SHELL", is also an incorrect way to identify what shell you are running, This command will tell you the user's default shell, i.e. the one defined in the passwd database.
Well, echo $SHELL will print the active shell.
I get different results whether i type that inside a zsh bash or sh script, but in the terminal, usualy you are right, it prints the default shell, since most ppl dont change the terminal its shell.
I'm not sure what you mean by active shell. I think of the value of environment variable SHELL as the path of the login shell. Here are several invocations of shells and the value of variable SHELL:
No. The SHELL var, where used/understood just says what shell to use if needed (e.g. .a sub shell created from another process). Doesn't have to be the shell defined in user's passwd entry at all, in fact has better chance of being set by the shell itself.
Jilliagre is right. E.g. bash sets SHELL to the user's default shell if not yet set.
The old Bourne shell does not do that, but these systems use the login program - that does it.
And you are right, too. Once SHELL is set (automatically or manually), many tools (e.g. shell-terminal) open this shell.
--
Traditionally /sbin contained statically-linked binaries. At that times /usr was a separate partition or even a separate disk. If /usr failed and the kernel could load from / then it was good to have statically linked tools under / , without the need of the /usr/lib/*.so
Indeed Solaris 9 and older have
% ls -l /bin/sh
-r-xr-xr-x 4 root root 95480 Nov 19 2008 /bin/sh
% ls -l /sbin/sh
-r-xr-xr-x 2 root root 306216 Nov 19 2008 /sbin/sh
% ldd /bin/sh
libgen.so.1 => /usr/lib/libgen.so.1
libsecdb.so.1 => /usr/lib/libsecdb.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libc.so.1 => /usr/lib/libc.so.1
libcmd.so.1 => /usr/lib/libcmd.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libmp.so.2 => /usr/lib/libmp.so.2
/usr/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
% ldd /sbin/sh
ldd: /sbin/sh: file is not a dynamic executable or shared object
For each fix in one of the shared libraries Sun had to provide a new /sbin/sh (to also contain the fix). This was cumbersome.
Solaris 10 changed to
% ls -l /bin/sh
lrwxrwxrwx 1 root root 13 Nov 7 2011 /bin/sh -> ../../sbin/sh
And in Solaris 11 Oracle has given up the Bourne shell
% ls -l /bin/sh
lrwxrwxrwx 1 root root 9 Jun 17 2013 /bin/sh -> i86/ksh93
% ls -l /sbin/sh
lrwxrwxrwx 1 root root 16 Jun 17 2013 /sbin/sh -> ../bin/i86/ksh93
The primary purpose of /sbin is system recovery. Of course it is used by the "superuser".
Following that sense /usr/sbin was created with further "superuser" tools (dynamically linked).
BTW Solaris 11 has
% ls -ld /sbin
lrwxrwxrwx 1 root root 10 Jun 17 2013 /sbin -> ./usr/sbin
And all Solaris have
ls -ld /bin
lrwxrwxrwx 1 root root 9 Jun 17 2013 /bin -> ./usr/bin
Now even RHEL 7 joins in - what a relief!
The /bin /usr/bin /sbin /usr/sbin "quadriga" is quite common in Unix,
Portable shell scripts should start with
PATH=/bin:/usr/bin:/sbin:/usr/sbin
and then use simple commands.
I have seen a thousand scripts that have adventurous workarounds (e.g. manually trying each command with various pathnames, storing them in variables or even in arrays - disgusting!).
I would advice for portable scripts to have their shebang adapted to point to the POSIX shell available on the target platform, e.g. on Solaris:
#!/bin/ksh
or even better for stricter compatibility:
#!/usr/xpg4/bin/sh
then have the scripts using this PATH:
PATH=$(getconf PATH):$PATH
and use POSIX commands, options and syntax when applicable. Adding /sbin and /usr/sbin to the PATH makes sense too if the scripts need to run administrative commands.
root@singapore # tail -2 .profile
#Prabhu # This command has been given here to auto switch to bash shell upon every login without changing the default shell for root user.
/usr/bin/bash
root@singapore # ps -p $$
PID TTY TIME CMD
21886 pts/3 0:00 sh