1

If after logging into my system I type: bash (to use bash subshell) and then try to run a bash script (e.g. example.sh), then does it matter if I do not put #!/bin/bash as the first line of the script or it is fine since I am already inside bash subshell?

mjm
  • 103
  • 1
  • 1
  • 3
  • I don't know, what happens when you try that? – Sumner Evans Oct 03 '17 at 21:19
  • 2
    @SumnerEvans, encouraging try-it-and-see isn't necessarily a good practice in the shell world -- runtime behavior depends on a bunch of variables, so it's easy for someone to decide that a practice is safe based on a simple test when it has serious caveats that test fails to uncover. – Charles Duffy Oct 03 '17 at 21:21
  • @mjm, ...for an example of such a less-than-obvious corner case: If you ran `find ... -exec ./otherscript {} +`, the execution of `otherscript` will fail outright without a shebang, no matter what shell starts `find`. – Charles Duffy Oct 03 '17 at 21:22

0 Answers0