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. NumPy:数组计算

    一.MumPy:数组计算 1.NumPy是高性能科学计算和数据分析的基础包.它是pandas等其他各种工具的基础.2.NumPy的主要功能: ndarray,一个多维数组结构,高效且节省空间 无需循环 ...

  2. Zookeeper安装(本地,伪分布式,集群)

    概述 ZooKeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization).命名服务(Namin ...

  3. Spring Boot的Listener机制的用法和实现原理详解

    之前在介绍了在spring-boot启动过程中调用runner的原理,今天我们介绍另外一种可以实现相似功能的机制:spring-boot的Listener机制. 通过注册Listener,可以实现对于 ...

  4. 检查URL的可用性脚本

    #!/bin/bash check_url() { HTTP_CODE=$(curl -o /dev/ -s -) ];then echo "Warning: $1 Access failu ...

  5. js两种写法执行速度比较

    记录 function test1(){ this.say = function(){} } function test2(){ this.say = function(){} return this ...

  6. 如何上传项目到Git

    1.首先下载Git,然后安装 我用的版本是Git-2.15.0-64-bit 2.在你的Git上创建一个新的Progect 创建完成后,会出现这样的窗口,红框圈出来的就是你的Git项目路径 3.在本地 ...

  7. Scrapy 框架 安装

    Scrapy 框架 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网页 ...

  8. .netcore读取配置文件

    setting.json { "compilerOptions": { "noImplicitAny": false, "noEmitOnError& ...

  9. JavaBean toString() - 将bean对象打印成字符串

    JavaBean toString方式 https://www.cnblogs.com/thiaoqueen/p/7086195.html //方法一:自动生成 @Override public St ...

  10. IT设备服务监控的方法论

    有方法论提导,在技战术方面才不会偏离目录. 使用服务级别作为关键语,召示着承诺和责任. https://www.circonus.com/2018/06/comprehensive-container ...