Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my Linux box, echo $SHELL results in /bin/csh. So I assume my default shell is c-shell. I am trying to understand the behavior of a shell script.
scenario 1 - script contains -

echo $1 $2 $3
echo $*
echo $argv[1] $argv[2]
echo $argv[*]
echo $#argv

output -

arg1 arg2 arg3
arg1 arg2 arg3 arg4
[1] [2]
./ line 4: [3]: command not found
  • So clearly the c-shell is not able to execute the last 4 lines in the script which should be executed by csh.

However - when I add the shebang line #!/bin/csh at the top of the script, it prints all the output correctly.

Question - Why is the csh not executing the last 4 lines correctly in first scenario and why do I explicitly have to include the shebang line?

share|improve this question
up vote 1 down vote accepted

When the file starts with #!/bin/csh, you explicitly tell the kernel to run the script with that program. But if there's no #! at the start of your file, execution fails – the exec() syscall fails – and your shell attempts to run the script using an even older method, by passing the file directly to /bin/sh.

The Bourne shell, sh, implemented this behavior way before #! appeared, and so scripts written this way expect to be run under sh or at least a compatible shell. csh is far from compatible, so it runs such scripts under sh. Your $SHELL is irrelevant.


Because many systems use either the standard version 6 or ver- sion 7 shells whose shell scripts are not compatible with this shell, the shell uses such a 'standard' shell to execute a script whose first character is not a '#', i.e., that does not start with a comment.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.