Bash script execution with and without shebang in Linux and BSD

后端 未结 2 1627
小鲜肉
小鲜肉 2020-11-30 07:50

How and who determines what executes when a Bash-like script is executed as a binary without a shebang?

I guess that running a normal script with shebang is

2条回答
  •  不知归路
    2020-11-30 08:37

    (Looks like Sorpigal has covered it but I've already typed this up and it may be of interest.)

    According to Section 3.16 of the Unix FAQ, the shell first looks at the magic number (first two bytes of the file). Some numbers indicate a binary executable; #! indicates that the rest of the line should be interpreted as a shebang. Otherwise, the shell tries to run it as a shell script.

    Additionally, it seems that csh looks at the first byte, and if it's #, it'll try to run it as a csh script.

提交回复
热议问题