Posted By: Anonymous
In bash script, what does
#!/bin/bash at the 1st line mean ?
UPDATE: Is there a difference between
That is called a shebang, it tells the shell what program to interpret the script with, when executed.
In your example, the script is to be interpreted and run by the bash shell.
Some other example shebangs are:
#!/bin/sh — Execute the file using sh, the Bourne shell, or a compatible shell #!/bin/csh — Execute the file using csh, the C shell, or a compatible shell #!/usr/bin/perl -T — Execute using Perl with the option for taint checks #!/usr/bin/php — Execute the file using the PHP command line interpreter #!/usr/bin/python -O — Execute using Python with optimizations to code #!/usr/bin/ruby — Execute using Ruby
and a few additional ones I can think off the top of my head, such as:
#!/bin/ksh #!/bin/awk #!/bin/expect
In a script with the bash shebang, for example, you would write your code with bash syntax; whereas in a script with expect shebang, you would code it in expect syntax, and so on.
Response to updated portion:
It depends on what
/bin/sh actually points to on your system. Often it is just a symlink to
/bin/bash. Sometimes portable scripts are written with
#!/bin/sh just to signify that it’s a shell script, but it uses whichever shell is referred to by
/bin/sh on that particular system (maybe it points to