Monday, December 15, 2014

Shell scripting : What if there are two shebang(#!) lines in the shell script?

Suppose if there are two she-bang (#!) lines in a shell script

#!/bin/bash

echo "First line"

#!/bin/csh

echo "Second line"

When we run the above script, will /bin/bash be the interpreter for executing the command echo "First Line"  and later  /bin/csh be the interpreter for executing the command echo "Second line"?

No. Only the first line is #!/bin/bash is the interpreter for the whole script. The second interpreter beginning with # is considered as a comment. Any line beginning with # following the first shebang line is considered as a comment.


No comments:

Post a Comment