A shebang (#!/bin/sh) is placed on the first line of a bash script, and it's usually followed on the second line by a comment describing what action the script performs. What if, for no particular reason, you decided to place the first command far beneath the shebang and the comment by, say, 10000 lines. Would that slow the execution of the script?
Shell – Distance of a command from a shebang
shebangshell-script
Best Answer
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 whileshort.sh
has none. Here are the results: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: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
andvery_long.sh
To create the script
long.sh
, I used the followingawk
command:To create
very_long.sh
, I only needed to modify the above code slightly: