以下脚本使用该-e选项运行,因此如果其中的任何命令失败,它将退出:
#!/bin/sh -e
command1 #script should fail if command1 fails
command2 #script should NOT fail if command2 fails
command3 #script should fail if command3 fails
Run Code Online (Sandbox Code Playgroud)
如何让脚本不失败command2?
您可以根据需要关闭设置:
#!/bin/sh
set -e
command1 #script should fail if command1 fails
set +e
command2 #script should NOT fail if command2 fails
set -e
command3 #script should fail if command3 fails
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2843 次 |
| 最近记录: |