shell 脚本中 “set -e” 的作用

时间:2019-06-13 21:18:03   收藏:0   阅读:1022

概述

  set -e 等同于 set -o errexit,当 shell 执行的时候,如果出现错误立即退出。

示例

$ ls
test.sh
rivsidn@rivsidn:~/test$ cat test.sh 
#! /bin/bash
set -e
touch aa
cp aa ./bb/
touch cc

 

  所示,如果不加 set -e 时候,会生成两个文件 aa, cc; 如果加 set -e 只会生成 aa 一个文件。

 

 

参考资料:

  https://blog.51cto.com/sf1314/2062713

原文:https://www.cnblogs.com/rivsidn/p/11019449.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!