4

Having super simple shell script like so:

echo "Hello World"

with no shebang line, the executable bit set on the file and called like so:

./my_sript

what is the interpreter used to run the script? How is it found by the system and where is the default interpreter defined?.

3

The default shell for this user (not the current shell) will be used. Have a look at /etc/passwd - it's defined there, and will be launched at login. You can use chsh to change the current user's default shell.

| improve this answer | |
1

I disagree with the jvb answer. Consider the following csh formatted script, without a shebang:

#
set x = 'a'
if ($x == 'a') then
   echo "running csh"
endif

On my machine, where my default shell is (t)csh, the result is:

anukis% ./shell-test
running csh

Now, edit the script to delete the top line:

set x = 'a'
if ($x == 'a') then
   echo "running csh"
endif

Now re-run it and the result is:

anukis% ./shell-test
./shell-test: 6: Syntax error: end of file unexpected (expecting "fi")

What's the difference? The ancient way to differenciate csh from (Bourne) sh: if the first line starts with an octothorpe ("#"), assume it's a C-shell script, otherwise a Bourne(-type) shell.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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