开发者

Linux shell strange situation

Does anyone know why the following script works?

#a-random-junk-string
echo HI

Th开发者_如何学运维e shell executes the echo command, and outputs HI. I thought that since there is no "!" after the "#", the shell would give an error.


If there is no #! specifying a specific interpreter, the kernel will not intercept and launch it with the specified program.

However, the current shell may still interpret it as a command file, which is what you are seeing take place.


When the shell is asked to run a file with the executable bit turned on then it will examine the file and determine if it begins with a shebang #! if it does then it will execute that command which will get it's program text from the remainder of the file.

If the file does not start with a shebang then the shell will attempt to execute it itself. This is what is happening for you and the shell interprets the first line as a comment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜