Search code examples
shelltcshshebang

Shebang's relation to current shell


If my current shell is a tcsh shell (confirmed with >echo $shell and >ps $$ etc.), do I have to write shebangs like #! bin/tcsh and have only that kind of scripts to run properly?

I made scripts with sh shebangs #! bin/sh and they run properly, although my shell was always a tcsh shell. My scripts had forloops, which are different in sh and tcsh.

Do I need to change my current tcsh shell into sh shell in order to run scripts with sh shebangs? Any help? Thanks!


Solution

  • IF your shebang lines were actually #! bin/sh then the reason that they worked correctly is because that path doesn't exist and your current shell is taking over running of the script.

    Fix the path in the shebang line to be a valid absolute path #!/bin/sh and I expect you will see the scripts start to fail.

    See http://www.in-ulm.de/~mascheck/various/shebang/ for more about the shebang line that you likely care about.