Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a Bash script without the shebang line

Tags:

bash

I wrote a bash script under CentOS and it was executed well. On another computer it was wrong. I forgot the shebang at the beginning, but why was it good on my computer? I assume it's a very beginner question, but I gave it a try. Thanks.

Updated: Another question popped up. What's the difference between executing with ./filename.sh and sh filename.sh?

like image 554
Lgn Avatar asked Mar 30 '12 14:03

Lgn


1 Answers

Not having a shebang in the beginning of your script will get it executed in whatever shell is currently running when the script was invoked. If you know for sure that the script will be launched from bash, and not from any other shell (ksh, csh, etc.), there is no need for a shebang, because the same interpreter will be launched.

like image 79
Blagovest Buyukliev Avatar answered Sep 30 '22 02:09

Blagovest Buyukliev