在'script.sh'中找不到命令(chmod +x mybinary)。
当运行脚本时,出现了 "Command not found (chmod +x mybinary) in 'script.sh'" 的错误提示。这个问题的原因是因为在脚本中修改了"PATH"变量的值,而"PATH"是一个用于搜索和执行文件的shell环境变量,因此无法再找到bin chmod命令。
要解决这个问题,可以采取以下方法:
1. 在脚本中使用绝对路径来执行chmod命令,而不是依赖于"PATH"变量:
if /bin/chmod +x "$P$BIN"; then echo "Added the executable bit to '$BIN'" else echo "Couldn't add the executable bit to '$BIN'" fi
2. 在更改"PATH"变量之前,将其备份并在使用chmod命令后进行恢复:
OLD_PATH=$PATH export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" if chmod +x "$P$BIN"; then echo "Added the executable bit to '$BIN'" else echo "Couldn't add the executable bit to '$BIN'" fi export PATH=$OLD_PATH
通过采取上述方法,可以解决"Command not found (chmod +x mybinary) in 'script.sh'"的问题,脚本将能够找到并执行chmod命令。