To find out, I created two shell files. Each starts with a shebang line and ends with the sole command date
. long.sh
has 10,000 comment lines while short.sh
has none. Here are the results:
$ time short.sh
Wed Nov 12 18:06:02 PST 2014
real 0m0.007s
user 0m0.000s
sys 0m0.004s
$ time long.sh
Wed Nov 12 18:06:05 PST 2014
real 0m0.013s
user 0m0.004s
sys 0m0.004s
The difference is non-zero but not enough for you to notice.
Let's get more extreme. I created very_long.sh
with 1 million comment lines:
$ time very_long.sh
Wed Nov 12 18:14:45 PST 2014
real 0m1.019s
user 0m0.928s
sys 0m0.088s
This has a noticeable delay.
Conclusion
10,000 comment lines has a small effect. A million comment lines cause a significant delay.
How to create long.sh
and very_long.sh
To create the script long.sh
, I used the following awk
command:
echo "date" | awk 'BEGIN{print "#!/bin/bash"} {for (i=1;i<=10000;i++) print "#",i} 1' >long.sh
To create very_long.sh
, I only needed to modify the above code slightly:
echo "date" | awk 'BEGIN{print "#!/bin/bash"} {for (i=1;i<=1000000;i++) print "#",i} 1' >very_long.sh
The shebang is working and cron has nothing to do with that. When a file is executed, if that file's content begins with #!
, the kernel executes the file specified on the #!
line and passes it the original file as an argument.
Your problem is that you seem to believe that SHELL
in a shell script reflects the shell that is executing the script. This is not the case. In fact, in most contexts, SHELL
means the user's prefered interactive shell, it is meant for applications such as terminal emulator to decide which shell to execute. In cron, SHELL
is the variable that tells cron what program to use to run the crontab entries (the part of the lines after the time indications).
Shells do not set the SHELL
variable unless it is not set when they start.
The fact that SHELL
is /bin/sh
is very probably irrelevant. Your script has a #!/bin/bash
line, so it's executed by bash. If you want to convince yourself, add ps $$
in the script to make ps
show information about the shell executing the script.
Best Answer
Typically shebang refers to just the
#!
(!
is typically called "bang", and it looks like "she" is a corruption of either "SHArp" or "haSH" for#
) -- the whole line is called a shebang lineIt does intentionally start with a comment character for backwards-compatibility with things that don't know how to handle it; the
!
is presumably just to distinguish it from a random comment starting the file, so a file that begins with# this is my script!
doesn't try to run thethis is my script!
interpreter