gpt4 book ai didi

bash - Shebang 后跟 rm 命令不是自删除脚本

转载 作者:行者123 更新时间:2023-12-04 18:06:06 29 4
gpt4 key购买 nike

我指的是本教程 http://www.tldp.org/LDP/abs/html/sha-bang.html#AEN226在 bash 上进一步提高我的知识,但我似乎无法使用网站中提到的脚本命令删除我的脚本。是我做错了什么还是代码本身有问题?

#!/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.

我也试过,

#!/bin/rm -f

那也是不行的。

最佳答案

shebang 符号表示按原样执行脚本时要使用的解释器 (./MyScript.sh)。

如果您显式声明解释器——如bash MyScript.sh——将否决shebang 行。所以我猜这就是这里发生的事情。

关于bash - Shebang 后跟 rm 命令不是自删除脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26293429/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com