首页 > 技术文章 > shell set 命令

rivsidn 2019-06-13 20:59 原文

概述

 

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

推荐阅读