[Techtalk] Comments in bash scripts
MMP - Barb Fox
mmp_fox at bellsouth.net
Sun Feb 15 20:39:46 EST 2004
Many shell scripting environments are written to read the very first line
of a shell script.
Example: IF shellscript begins with a #!/bin/sh, then the script will be
run under a Bourne shell environment. If the line is #!/usr/sbin/perl,
then the script will be interpreted with the perl program located in
/usr/sbin, etc. If the #! is NOT the first line of a shell script, then
the #! simply becomes a normal comment.
When is this important? When you write a program using bash constructs,
you should put #!/bin/bash as the first line, then other users who are
running in cshells, for example, would still be able to run your program
without knowing it was a bash shell script. Otherwise they would get
syntax errors and have to manually execute a bash shell to make the script
work.
Hope that helps!
Barb Fox
mmp_fox at bellsouth.net
At 06:06 PM 2/15/2004, you wrote:
>Someone told me recently that you mustn't put comments before the
>hash bang line in a bash script because it's bad practice. Why is
>that?
>
>Thanks
>Berenice
More information about the Techtalk
mailing list