5344
5432
1万
管理员
本站资源如失效,请点击反馈!
$ bash script.sh
$ set
#!/usr/bin/env bashecho $aecho bar
$ bash script.shbar
#!/usr/bin/env bashset -uecho $aecho bar
$ bash script.shbash: script.sh:行4: a: 未绑定的变量
set -o nounset
#!/usr/bin/env bashset -xecho bar
$ bash script.sh+ echo barbar
set -o xtrace
#!/usr/bin/env bashfooecho bar
$ bash script.shscript.sh:行3: foo: 未找到命令bar
command || exit 1
# 写法一command || { echo "command failed"; exit 1; }# 写法二if ! command; then echo "command failed"; exit 1; fi# 写法三commandif [ "$?" -ne 0 ]; then echo "command failed"; exit 1; fi
command1 && command2
#!/usr/bin/env bashset -efooecho bar
$ bash script.shscript.sh:行4: foo: 未找到命令
set +ecommand1command2set -e
#!/bin/bashset -efoo || trueecho bar
set -o errexit
#!/usr/bin/env bashset -efoo | echo aecho bar
$ bash script.shascript.sh:行4: foo: 未找到命令bar
#!/usr/bin/env bashset -eo pipefailfoo | echo aecho bar
$ bash script.shascript.sh:行4: foo: 未找到命令
# 写法一set -euxo pipefail# 写法二set -euxset -o pipefail
$ bash -euxo pipefail script.sh
使用道具 举报
本版积分规则 发表回复 回帖后跳转到最后一页
手机版|飞雪团队
GMT+8, 2024-11-24 05:31 , Processed in 0.118828 second(s), 24 queries , Gzip On.
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.