This question already has an answer here:

I have some points I want to understand: I have a script written in bash syntax and does not contain the shebang line (#!/bin/bash) and my default shell is tcsh.

  • when giving execute permission to the file and run it in the default shell (tcsh) by typing the full path of the file, it runs correctly. How the script is run correctly in tcsh and without typing the shebang line?
  • for the same file in the default shell tcsh if I use the source command to run it, it gives syntax error (even if I used the shebang bash line) why?

after some trials I found the following:Thanks, this seems correct I did some trials and reached the following: - Using source (dot operator is alias only in bash) command to run a file: - Executes it even if it has no execute permission - Runs it using the current shell irrespective of the shebang line - If the shebang line exists and the file is run by typing its name (total path) ( here need execute permission), the file is run using the shell in the shebang line. If the shebang line does not exist and run by the name, the bash is always used in my case irrespective of the current shell. I do not why, is it because the bash comes first in the /bin file??????? can you check that with me

marked as duplicate by Kusalananda bash Feb 20 '18 at 18:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


If an executable script does not have a shebang line, it is executed by /bin/sh. If you use source to execute it, it is run within the current shell:

$ cat s.sh
echo "shell=$shell"
echo "BASH=$BASH"
$ ./s.sh
$ tcsh
[~]% ./s.sh
[~]% source s.sh
BASH: Undefined variable.
  • Hmmm... I think it may be sh running the script that second time though, which is why shell is not set. – Kusalananda Feb 20 '18 at 18:42
  • no, it runs /bin/sh, as do dash and zsh (I tested). – ilkkachu Feb 20 '18 at 19:55

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