Shell 脚本中 set -ex 命令的作用
2023-09-14 09:15:40 时间
#!/bin/bash -ex
shell 命令 set -ex,稍有常识的人都能看出,这是 set 命令加上了 -e 和 -x 两个参数 (废话么这不是)。那么,我就把这两个参数拆开,分别说一下它在脚本中的用处。
set -e
这个参数的含义是,当命令发生错误的时候,停止脚本的执行
#!/bin/bash
echo 1 && rm non-existent-file && echo 2
等同
#!/bin/bash
set -e
echo 1
rm non-existent-file # which will fail
echo 2
set -x
-x 参数的作用,是把将要运行的命令用一个 + 标记之后显示出来
#!/bin/bash
set -ex
echo 1
rm non-existent-file # which will fail
echo 2
输出
+ echo 1
1
+ rm non-existent-file
rm: non-existent-file: No such file or directory
相关文章
- 关于java.io.IOException: HADOOP_HOME or hadoop.home.dir are not set.的问题
- ORA-00824: cannot set sga_target due to existing internal settings, see alert log for more information
- python 使用set对列表去重,并保持列表原来顺序
- Vue Nuxtjs Cannot set property 'render' of undefined解决方法
- SAP BSP set server cache via CL_BSP_UTILITY-SET_BROWSER_CACHE
- SAP CRM呼叫中心和社交媒体集成的所有BC set实现列表
- Hive / ClickHouse 行转列函数 collect_set() / groupUniqArray()
- 【错误记录】Tinker 热修复示例运行报错 ( Execution failed for task ‘:app:tinkerProcessD‘ . tinkerId is not set!!! )
- PostgreSQL的学习心得和知识总结(四十)|语法级自上而下完美实现MySQL数据库UPDATE命令的 set使用别名 的实现方案
- Android反射set/get系统属性SystemProperties(三)
- redis的set命令学习
- 批处理命令——set
- 使用Replication Controller、Replica Set 管理Pod
- 【STL】set集合