ios - shell脚本中set -e是什么意思
阿神
阿神 2017-04-17 11:51:11
[iOS讨论组]

我看了一下某个脚本,最开始的两行是

set -e
set -o pipefail

请问这两句是什么意思呢?

阿神
阿神

闭关修行中......

全部回复(2)
ringa_lee

$ set -e

这行代码之后的任何代码,如果返回一个非0的值,那么整个脚本立即退出,官方的说明是为了防止错误出现滚雪球的现象

$ set -o pipefail

原文解释如下:

If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status,or zero if all commands in the pipeline exit successfully. This option is disabled by default.

可理解为:

告诉 bash 返回从右到左第一个以非0状态退出的管道命令的返回值,如果所有命令都成功执行时才返回0

迷茫

多谢楼上回答,我备份脚本正好需要set -e

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号