dd this to the beginning of the script:

set -e

This will cause the shell to exit immediately if a simple command exits with a nonzero exit value. A simple command is any command not part of an if, while, or until test, or part of an && or || list.

See the bash(1) man page on the "set" internal command for more details.

I personally start almost all shell scripts with "set -e". It's really annoying to have a script stubbornly continue when something fails in the middle and breaks assumptions for the rest of the script.

shell script exit if any command fails的更多相关文章

  1. Shell script fails: Syntax error: “(” unexpected

    Shell script fails: Syntax error: “(” unexpected google 一下. http://unix.stackexchange.com/questions/ ...

  2. How to use ftp in a shell script

    转载How to use ftp in a shell script How to use ftp in a shell script Bruce EdigerBruce Ediger's home ...

  3. shell script练习

    执行脚本的几种方式: 1. sh a.sh 或者  bash a.sh  调用的是 /bin/bash 进程执行的,所以脚本不需要执行权限. 2. 直接使用绝对路径执行, /home/script/a ...

  4. shell script入门

    从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更加复杂的操 ...

  5. shell script 入门 笔记

    shell script 入门 在 shell script 注意必须使用完全相同写在下面: 1.  指令的运行是从上而下.从左而右的分析与运行: 2.  指令的运行就如同第五章内提到的: 指令.选项 ...

  6. 第13章 学习shell script

    由于博客园中dollar符号有别的意义,所以文中的dollar符号使用¥表示 第一个script [root@localhost script]# cat -n sh01.sh #!/bin/bash ...

  7. 学习shell script

    摘要:概述.script的编写.test命令.[]判断符号.默认变量($1...).if...then条件判断式. 一.概述 [什么是shell script] 针对shell所写的脚本,将多个命令汇 ...

  8. Shell script之How to write

    Write shell script: 1) Editor like vi or mcedi 2) Set execute permission for your script chmod  perm ...

  9. shell script简单笔记

    变量 shell script是一种脚本语言,变量的定义是通过 myName=HYB 这样的形式定义的. 当存在空格时,可以通过双引号或单引号将其变为字符串.双引号不进行转义,单引号将内容进行转义为一 ...

随机推荐

  1. Memcached简介及环境安装

    Memcached简介及环境安装 author:SimpleWu 简介 Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached是以LiveJournal旗下Danga ...

  2. python+selenium十四:xpath和contains模糊匹配

    xpath可以以标签定位,也可以@任意属性: 如:以input标签定位:driver.find_element_by_xpath("//input[@id='kw']") 如:@t ...

  3. Spring 整合 Quartz 实现动态定时任务

    复制自:https://www.2cto.com/kf/201605/504659.html 最近项目中需要用到定时任务的功能,虽然Spring 也自带了一个轻量级的定时任务实现,但感觉不够灵活,功能 ...

  4. Could not create SSL/TLS secure channel.

    解决办法: ServicePointManager.Expect100Continue = true;ServicePointManager.SecurityProtocol = SecurityPr ...

  5. Java接口自动化测试之HTTPClient学习(四)

    pom.xml  文件中dependency <dependencies> <dependency> <groupId>org.testng</groupId ...

  6. HDU 3336 Count the string(next数组运用)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. 转: 解压Assets.car (iOS加密资源)

    今天想获取APP的资源,但是查看xxx.app文件夹里面,缺少了大部分资源.在文件夹里面发现Assets.car这个文件,发现文件很大有40多M,猜想图片资源会不会被压缩到这里面了,所以就网络上查了下 ...

  8. IDEA 小白采坑

    IDEA Debug状态下,断点第一次可以进去,之后都不能进去 调试时候不要用Ctrl+F9,如果是点击Tool Windows 上的图标的话,也要注意改图标的快捷键是不是Ctrl+F9 Ctrl+F ...

  9. vue 踩坑记录

    1.绑定双击事件用 @dblclick 不要用@ondblclick  在vue中@=on 2.Vue中路由跳转踩坑. 比如我的路由如下定义 routes: [ { path: "/&quo ...

  10. sinoces 2013 消费电子

    转眼距离上次看消费电子(http://www.cnblogs.com/sun8134/archive/2012/07/08/2581997.html)又过了一年 也到了今年的消费电子展… 结果一天小雨 ...