#!/bin/sh
echo "install 1"
echo "install 2"
[ $? -eq 0 ] || exit $?;
cyberciti
[ $? -eq 0 ] || exit $?;
echo "install 3"
echo "install 4"
上述脚本在第 4 行失败 (cyberciti
)。在进行必要的更正后,如何获取行号并从该行开始重新运行脚本,并跳过已执行的命令?
最佳答案
要跳过前 4 行(因此从第 5 行开始):
tail --lines=+5 script.sh | sh
根据 the man page , --lines=K
表示输出最后K行,而不是最后10行;或使用 -n +K 从第 K 开始输出
。
归功于 Aaron Digulla他的回答here .编辑:感谢l0b0为了防止我的 cat
来自 taking over the world !
关于linux - 如何从特定行启动 shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29539949/