test script to identify SHELL

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

where am I missing . PLease advice .

Thanks

have you tried:

echo $0

the $SHELL variable refers to the user's default shell (in /etc/passwd) - it may not reflect the shell that the user is currently running.

Read the error message. What command is not found? Is that the command you are trying to execute?

You are missing spaces before and after brackets:

if [ "$SHELL" = "$BASH" ]

Note that $SHELL doesn't necessarily contain the shell you are currently running; it contains your default shell.

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.

Thankyou .

if you put "echo $0" inside the script , it will give the script name .

Thanks

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
./vartest.sh $0
the shell is -bash

Thankyou .

My problem is it's not seperate script . I have to include it in another script .

can you think of any other logic to identify the shell inside another script ..

#!/bin/bash

if [ "$SHELL"  == "/bin/bash" ]
then
    echo "blah"
else
    echo "aaa"
fi

Thanks

Why do you need to know what shell it is?

It is better to test for the features you want.

You can check for variables $BASH_VERSION and $KSH_VERSION (the latter only in pdksh).

#!/bin/sh

pid="$$"
echo "myShell->[`ps -o 'pid,comm' -p "${pid}" | nawk 'FNR==2{print $2}'`]"

YMMV - not generic

Using any standard version of ps (and no other external command) in any Bourne-type shell:

ps -o comm -p "$$" | { read; read comm; echo "$comm"; }

However, that doesn't necessarily tell you anything about the shell, particularly if it's sh.

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}" ] .