I am new to BASH and writing a small script to identify the SHELL .
#!/bin/bash
BASH='/bin/bash'
KSH='/bin/ksh'
if [$SHELL == "$BASH"]
then
echo "it's Bash"
else
echo "it's not Bash"
fi
$ bash -x a.sh
+ BASH=/bin/bash
+ KSH=/bin/ksh
+ '[/bin/bash' == '/bin/bash]'
a.sh: line 4: [/bin/bash: No such file or directory
+ echo 'it'\''s not Bash'
it's not Bash
You need a blank between both variables and the square brackets, otherwise neither shell can parse it correctly. And it would be advisable to put the $SHELL variable in quotes too.
Having said "echo $0", this won't work inside the shell script.
Calling $0 inside a sh/bash/ksh script will recall the name of the script.
You can pass this TO your script at the command line.
For example:
cat vartest.sh
#!/bin/sh
usage()
{
echo "Usage:"
echo " $0 \$0"
}
if [ $# -lt 1 ] ; then
echo "Don't forget to send the shell information"
usage
exit 1
fi
echo "the shell is $1"
exit 0
./vartest.sh
Don't forget to send the shell information
Usage:
./vartest.sh $0
I don't think that $SHELL is the right variable to test. Anyway, on a point of syntax the "==" is not valid in "test" when it is not bash.
cfajohnson approach to find a suitable variable which is only set by that shell is better. Use "if [ -z "${SUITABLE_VARIABLE}" ] .