Is there a TRY CATCH command in Bash?

No.

Bash doesn't have as many luxuries as one can find in many programming languages.

There is no try/catch in bash; however, one can achieve similar behavior using && or ||.

Using ||:

if command1 fails then command2 runs as follows

command1 || command2

Similarly, using &&command2 will run if command1 is successful

The closest approximation of try/catch is as follows

{ # try

    command1 &&
#save your output } || { # catch
# save log for exception
}

Is there a TRY CATCH command in Bash的更多相关文章

  1. chroot: cannot run command `/bin/bash': No such file&nbs

    最近在使用chroot去重新的挂载一个根目录,总是出现上面的问题,很烦,好久了没有解决, 然后自己就写了一个复制依赖库的脚本,然后发现可以切换了,然后就重新试着去挂载根目录 终于发现了原因. ---- ...

  2. chroot: failed to run command `/bin/bash': No such file or directory

    1 使用chroot命令时报错如下: testupgrade:/ # chroot /sb chroot: cannot change root directory to /sb: No such f ...

  3. Bash For Loop Examples

    How do I use bash for loop to repeat certain task under Linux / UNIX operating system? How do I set ...

  4. Bash的几个知识点

    1. 区别 builtin command, external command,bash script. 用builtin command(hash.type.command),而不是which命令( ...

  5. Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh

    Hyperpolyglot Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh grammar | quoting and escaping | charactersvar ...

  6. RH033读书笔记(11)-Lab 12 Configuring the bash Shell

    Sequence 1: Configuring the bash Shell Deliverable: A system with new aliases that clear the screen, ...

  7. bash, sh, dash 傻傻分不清楚

    原文链接,转载请注明出处: http://www.happycxz.com/m/?p=137 常见shell类型 Bourne shell (sh) UNIX 最初使用,且在每种 UNIX 上都可以使 ...

  8. 什么是shell? bash和shell有什么关系?

    什么是shell? bash和shell有什么关系? 博客分类: Linux   什么是Shell?      shell是你(用户)和Linux(或者更准确的说,是你和Linux内核)之间的接口程序 ...

  9. Docker-compose command 有多个命令例子

    cat docker-compose.yml version: '3.4' services: klvchen: image: python_django:19.03.0 ports: - 8000: ...

随机推荐

  1. Java语法基础常见疑惑解答

    1. 类是java的最小单位,java的程序必须在类中才能运行 2. java函数加不加static有何不同 java中声明为static的方法称为静态方法或类方法.静态方法可以直接调用静态方法,访问 ...

  2. Java的动手动脑(五)

    日期:2018.11.1 星期四 博客期:021 Part1: 运行代码 class Grandparent { public Grandparent() { System.out.println(& ...

  3. mysql老是停止运行该怎么解决

    你可能还会遇到无法启动mysql的错误 解决方法如下:

  4. bat 获取拖放文件路径或名称

    获取路径: @echo offset path=%~dp1echo %path%pause 获取路径及名称: @echo offset path=%~dp1%~nx1echo %path%pause

  5. 读书笔记——《You Don't Know JS》

    第一部:<You don't know JS: this & Object prototype> 第三章 Object 对象常量 var myObject = {}; Object ...

  6. 洛谷 P1217

    题目链接如下https://www.luogu.org/problemnew/show/P1217 找出a到b 是回文数并且是素数的数. 这还不简单 前两天刚学的线性筛素数.卡卡卡卡一顿猛敲.最后一个 ...

  7. C#学习-静态

    有提过类的成员,有字段.属性.方法和构造函数等,也可以使用static关键字将其声明为类的静态成员. 静态成员属于类级别的概念,它不属于类的实例. 可以使用static关键字来声明静态字段,静态字段与 ...

  8. Linux 命令行敲命令 光标移动快捷键

    在单词之间跳转,使用Ctrl+左右键. Ctrl+a跳到本行的行首, Ctrl+e则跳到页尾. Ctrl+u删除当前光标前面的文字 ctrl+k-删除当前光标后面的文字 Ctrl+w和Alt+d-对于 ...

  9. 如何扩展Orchard

    翻译自: http://msdn.microsoft.com/en-us/magazine/hh708754.aspx     动态类型系统 Content item是Orchard中的原子, 比如b ...

  10. activemq 控制面板里Number Of Pending Messages、 Messages Enqueued等含义解释

    项目中在API登录接口采用了ActiveMQ消息队列中间件,采用三台MQ做集群