Your script works flawlessly in bash , so I presume you run it with ksh . man ksh :
BTW, what you are doing is a test for a non-zero string e.g. "/usr/bin/bash", not for the existence of a file or command... Why not test for "executable"?
Maybe the current shell does not match the dot rc file shell. Try something like:
if [[ -s ~/.bashrc && $BASH = *bash ]]; then
echo running bash
source ~/.bashrc;
elif [[ -s ~/.kshrc && $SHELL = *ksh ]]; then
echo running ksh
source ~/.kshrc;
else
echo No rc file found for current shell
fi
I am missing something.
By default bash sources a file .bashrc if one exists in the current working for each "new" bash invocation. The same is true for ~.kshrc . Each "new" invocation of ksh sources the .kshrc file in the current working directory if it exists.
Per the man pages for each shell.
An example new: executing a script that has a shebang: #!/bin/bash , same for ksh
So why write a script which does exactly what default behavior of your shell already does for you? Good shell coding practice is to place a shebang on the first line, so it is clear what envoronment the shell requires. If bash is not in the PATH then #!/bin/bash will fail which is what you want.
I gave you a pointer in your previous thread on this subject. Forcing a shell to source the .bashrc file does not turn it into bash. Your default shell when logging in will be in the $SHELL variable (unless somebody knows better). So if you cannot change your default shell to bash try something like this at the end of your .profile:
case "$SHELL" in
*bash) . ./.bashrc ;;
*ksh)
for b in /bin/bash /usr/bin/bash /usr/local/bin/bash
do
if [ -x "$b" ]
then
SHELL=$b
export SHELL
exec $SHELL
fi
done
. .kshrc
;;
esac
. ./.kshrc ;;
esac