Writing a Bash script without the shebang line

前端 未结 2 1107
慢半拍i
慢半拍i 2020-12-21 00:16

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 a

相关标签:
2条回答
  • 2020-12-21 00:37

    If execve fails for your script, which it will, /bin/sh will be used. On one system /bin/sh may be a POSIX sh and on another it may be an alias for bash; your script probably relies on bash features.

    0 讨论(0)
  • 2020-12-21 00:50

    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.

    0 讨论(0)
提交回复
热议问题