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. RefineDet算法笔记

    ---恢复内容开始--- 一.创新点 针对two-stage的速度慢以及one-stage精度不足提出的方法,refinedet 包括三个核心部分:使用TCB来转换ARM的特征,送入ODM中进行检测: ...

  2. bs4

  3. Java并发编程基础-ReentrantLock的机制

    同步锁: 我们知道,锁是用来控制多个线程访问共享资源的方式,一般来说,一个锁能够防止多个线程同时访问共享资源,在Lock接口出现之前,Java应用程序只能依靠synchronized关键字来实现同步锁 ...

  4. LeetCode(89):格雷编码

    Medium! 题目描述: 格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异. 给定一个代表编码总位数的非负整数 n,打印格雷码序列.格雷码序列必须以 0 开头. 例如,给定 ...

  5. 剑指offer 二叉搜索树和双向链表

    剑指offer 牛客网 二叉搜索树和双向链表 # -*- coding: utf-8 -*- """ Created on Tue Apr 9 18:58:36 2019 ...

  6. delete web server(nginx)

    #!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" #conf_dir2="/usr/local/apache2/ ...

  7. 5分钟了解swagger

    5分钟了解swagger https://blog.csdn.net/i6448038/article/details/77622977 随着互联网技术的发展,现在的网站架构基本都由原来的后端渲染,变 ...

  8. Task.Run()任务执行

    1)Task本身就是异步执行的(4.5的那个类). 2)控制数量和终止线程问题可以考虑这个模式: static async void RunAsync() { CancellationTokenSou ...

  9. Win8.1 查看 “Windows 体验指数“

    啥是 Windows 体验指数 ? 引用MS的介绍: http://windows.microsoft.com/zh-cn/windows7/products/features/windows-exp ...

  10. BETA准备

    过去存在的问题 文档问题 未能事先做好设计文档,且小程序与后端数据库接口存在问题 界面问题 原型图设计花的时间较少,小程序设计界面仍相对粗糙,前端成员css元素应用经验不足 小程序界面之间对接存在问题 ...