Dmi*_*sky 6 unix linux bash shell
我正在阅读Advanced Bash-Scripting Guide的第2章,我在脚注中读到了这个脚本:
#!/bin/rm
# Self-deleting script.
# Nothing much seems to happen when you run this... except that the file disappears.
WHATEVER=85
echo "This line will never print (betcha!)."
exit $WHATEVER # Doesn't matter. The script will not exit here.
# Try an echo $? after script termination.
# You'll get a 0, not a 85.
Run Code Online (Sandbox Code Playgroud)
通常rm
接受一个参数并删除该文件.在这里,rm
不知何故知道对它正在执行的脚本采取行动.这是否意味着当shell遇到#!
它时,它会将(完全限定的?)路径传递给该文件,作为之后指定的程序的参数#!
?
是的,当您说“它将(完全限定?)路径传递给该文件作为 #! 之后指定的程序的参数”时,您是完全正确的。
这就是为什么 shell 脚本以#!/bin/sh
或 类似的开头,而 Python 脚本以#!/usr/local/bin/python
.
“shebang”行旨在运行脚本解释器,但可以指定任何可执行文件。
归档时间: |
|
查看次数: |
2597 次 |
最近记录: |