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. centos7查看yum安装的软件及路径

    rpm -qa 查看所有已安装软件名称 rpm -ql 软件名 显示软件的安装路径

  2. LeetCode(84): 柱状图中最大的矩形

    Hard! 题目描述: 给定 n 个非负整数,用来表示柱状图中各个柱子的高度.每个柱子彼此相邻,且宽度为 1 . 求在该柱状图中,能够勾勒出来的矩形的最大面积. 以上是柱状图的示例,其中每个柱子的宽度 ...

  3. LeetCode(65):有效数字

    Hard! 题目描述: 验证给定的字符串是否为数字. 例如:"0" => true" 0.1 " => true"abc" =& ...

  4. XSS-HTML&javaSkcript&CSS&jQuery&ajax

    1.设置不同的样式列表 <style> ul.a{list-style-tyrp:circle;}    ul.b{list-style-type:square;}   ul.c{list ...

  5. Nginx详解十一:Nginx场景实践篇之Nginx缓存

    浏览器缓存: HTTP协议定义的缓存机制(如:Expires.Cache-control等) 当浏览器第一次请求的时候,浏览器是没有缓存的 第二次请求开始就有缓存了 校验过期机制 配置语法-expir ...

  6. ajax---异步请求对象的属性和方法

    方法: 1).open(method.url,asyn):创建请求,(post.get)asyn:表示同步(false)还是异步(true)提交 ,默认true 2)send(body) 发送请求,b ...

  7. druid配置oracle遇到: 未找到要求的 FROM 关键字 errorCode 923, state 42000

    2018年05月29日 16:41:17 阅读数:518 问题背景 项目要连接oracle数据,采用的是durid连接池,但是基本配置下来,运行时发现了这个错误. 方案 可能有的一个错误就是,拼凑sq ...

  8. 论文阅读笔记二十二:End-to-End Instance Segmentation with Recurrent Attention(CVPR2017)

    论文源址:https://arxiv.org/abs/1605.09410 tensorflow 代码:https://github.com/renmengye/rec-attend-public 摘 ...

  9. linux基础练习题(2)

    Linux命令作业(关卡二) 练习题1 理解操作系统的作用,以及各种操作系统的不同 要求: 为什么要有OS?没有OS能行吗?原因是什么? Linux内核指的是什么? Linux主要应用在哪些地方? 使 ...

  10. 006-Python函数

    Python函数(def) 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段.Python提供了许多内建函数,比如print().但你也可以自己创建函数,这被叫做用户自定义函数.函数能 ...