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

概述

  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

猜你喜欢

转载自www.cnblogs.com/rivsidn/p/11019449.html
今日推荐