Oct 10, 2018

[HDGEM] Why put #!/bin/bash at the beginning of a script file?

It's a convention so the *nix shell knows what kind of interpreter to run.

Scripts can be in bash, python, perl, ruby, PHP, etc, etc. For example, you might see "!/bin/perl" or "/bin/perl5".

Under *nix, associating a suffix with a file type is merely a convention, not a "rule". An "executable" can be a binary program, any one of a million script types and other things as well. Hence the need for "#!/bin/bash".

The exclamation mark ("!") is affectionately called "bang". The shell comment symbol ("#") is sometimes called "hash".

Posted By Blogger to HDGEM at 3/13/2017 12:33:00 PM