Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have a script similar following one:


if [ $var == "ABC" ]
   echo True
   echo False

Above code does not work in Solaris Sparc and Solaris X64. It is showing == undefined. Above code works fine If I replace == with =.

Strange thing is If I ran above code without any change by following method it is working.


According to my understanding the script should not work even with bash, as at the top of the script I am using #!/bin/sh which does not support the == as the comparison operator.

Can anyone please explain why it does work when I am running the script as mentioned above.

Note: I am aware of that bash does recognize == and =.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

The first line of the script is called the #! line (sometimes called the "shebang" line).

It is only used when a script is executed directly, as in



When you run an executable, the operating system looks at the first two bytes to tell what type of program it is.

When you run


the operating system sees that the first two bytes of ./ are #!, so it knows the program is a script.

It reads the rest of the line to see which shell1 it should use to run the script. In this case, the rest of the line is /usr/bin/sh, so it runs /usr/bin/sh test.sh2.

When you run


it finds bash in /usr/bin/bash3. It sees that the first two bytes of /usr/bin/bash are not #!, so it runs /usr/bin/bash without even looking at the first line of

In both cases, sh and bash actually ignore the shebang line because any line beginning with # is a comment. The # only has this magic effect because of the operating system, not the shell.

More info:


  1. In fact, it can be any program, it doesn't have to be a shell.
  2. Actually more like execl("./", "/usr/bin/sh", "./", NULL).
  3. /bin/sh on most Linux systems, but the question was about Solaris.
share|improve this answer

Running the script with bash (running bash means that the script is interpreted with bash, not the Bourne shell (/bin/sh). That's why it works. Bash ignores the #!/bin/sh because it is a comment. It's only your OS's program loader that starts /bin/sh if you run the shell script without bash (running ./ for example).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.