我正在阅读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.
通常rm
接受一个参数并删除该文件。在这里,rm
不知何故知道对它正在执行的脚本采取行动。这是否意味着当 shell 遇到 时#!
,它会将该文件的(完全限定?)路径作为参数传递给在 之后指定的程序#!
?