Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Does the shebang determine the shell which runs the script?

This may be a silly question, but I ask it still. If I have declared a shebang
#!/bin/bash 

in the beginning of my_shell_script.sh, so do I always have to invoke this script using bash
[my@comp]$bash my_shell_script.sh

or can I use e.g.
[my@comp]$sh my_shell_script.sh

and my script determines the running shell using the shebang? Is it the same happening with ksh shell? I'm using AIX.
by

1 Answer

Bharatgxwzm
It is called a shebang or a "bang" line.

It is nothing but the absolute path to the Bash interpreter.

It consists of a number sign and an exclamation point character (#!), followed by the full path to the interpreter such as /bin/bash.

All scripts under Linux execute using the interpreter specified on a first line Almost all bash scripts often begin with #!/bin/bash (assuming that Bash has been installed in /bin) This ensures that Bash will be used to interpret the script, even if it is executed under another shell. The shebang was introduced by Dennis Ritchie between Version 7 Unix and 8 at Bell Laboratories. It was then also added to the BSD line at Berkeley .

Ignoring An Interpreter Line (shebang)

If you do not specify an interpreter line, the default is usually the /bin/sh. But, it is recommended that you set #!/bin/bash line.

Login / Signup to Answer the Question.