Writing a bash script without a shebang string

I wrote a bash script under CentOS and it performed well. On the other computer, this was wrong. At first I forgot about the shibang, but why was it good on my computer? I guess this is a very newbie, but I tried. Thank.

Updated: Another question has arisen. What is the difference between executing with ./filename.sh and sh filename.sh ?

+5
source share
2 answers

The absence of shebang at the beginning of your script will lead to its execution in any shell that is currently running when the script is called. 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 shebang, because the same interpreter will be launched.

+4
source

If it execvefails for your script, what will /bin/shbe will be used. There /bin/shmay be POSIX on one system sh, and an alias for on the other bash; your script probably relies on bash.

+4
source

All Articles