eri Asked:2022-08-31 19:20:43 +0800 CST2022-08-31 19:20:43 +0800 CST 2022-08-31 19:20:43 +0800 CST exit 在有条件的脚本中不起作用 772 #!/bin/bash [ "x$(tail -n+11 $0 | md5sum)" = "x$(head -n10 $0 | tail -n1)" ] || (echo "поврежден"; exit 1); echo "corrupted" 写入,但退出 1 不起作用。如何重写才能工作? linux 1 个回答 Voted Best Answer Alexey Ten 2022-09-01T14:48:05+08:002022-09-01T14:48:05+08:00 改写为正常if。括号在exit子 shell 中运行命令,而不是在主 shell 中运行。 if [ "x$(tail -n+11 $0 | md5sum)" = "x$(head -n10 $0 | tail -n1)" ]; then echo "поврежден" exit 1 fi 但是如果你真的想要,那么你需要使用花括号: [ "x$(tail -n+11 $0 | md5sum)" = "x$(head -n10 $0 | tail -n1)" ] || { echo "поврежден"; exit 1; } bash 中的复合命令。
改写为正常
if
。括号在exit
子 shell 中运行命令,而不是在主 shell 中运行。但是如果你真的想要,那么你需要使用花括号:
bash 中的复合命令。