Is there a TRY CATCH command in Bash
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的更多相关文章
- chroot: cannot run command `/bin/bash': No such file&nbs
最近在使用chroot去重新的挂载一个根目录,总是出现上面的问题,很烦,好久了没有解决, 然后自己就写了一个复制依赖库的脚本,然后发现可以切换了,然后就重新试着去挂载根目录 终于发现了原因. ---- ...
- 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 ...
- Bash For Loop Examples
How do I use bash for loop to repeat certain task under Linux / UNIX operating system? How do I set ...
- Bash的几个知识点
1. 区别 builtin command, external command,bash script. 用builtin command(hash.type.command),而不是which命令( ...
- Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh
Hyperpolyglot Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh grammar | quoting and escaping | charactersvar ...
- RH033读书笔记(11)-Lab 12 Configuring the bash Shell
Sequence 1: Configuring the bash Shell Deliverable: A system with new aliases that clear the screen, ...
- bash, sh, dash 傻傻分不清楚
原文链接,转载请注明出处: http://www.happycxz.com/m/?p=137 常见shell类型 Bourne shell (sh) UNIX 最初使用,且在每种 UNIX 上都可以使 ...
- 什么是shell? bash和shell有什么关系?
什么是shell? bash和shell有什么关系? 博客分类: Linux 什么是Shell? shell是你(用户)和Linux(或者更准确的说,是你和Linux内核)之间的接口程序 ...
- Docker-compose command 有多个命令例子
cat docker-compose.yml version: '3.4' services: klvchen: image: python_django:19.03.0 ports: - 8000: ...
随机推荐
- swift项目初始化并添加忽略文件Swift.ignore
1 先去GitHub上去把最新的忽略文件下载下载 https://github.com/github/gitignore 2 然后找到Swift.gitignore 把里面的 pod 前面的# 删除 ...
- respberry2b + android5.1
链接: http://pan.baidu.com/s/1kUf6UtL 密码: xz4g 安装教程:http://tieba.baidu.com/p/3963061007 如果安装后打开相册崩溃,则下 ...
- PyCharm设置字体风格
设置字体风格:File—Setting—Editor-Color Scheme-Color Scheme Font-把Scheme设置为:WarmNeon
- Python元组(tuple)
元组(tuple)是Python中另一个重要的序列结构,与列表类型,也是由一系列按特定顺序排列的元素组成,但是他是不可变序列.在形式上元组的所有元素都放在"()"中,两个元素使用& ...
- 一个简单的binlog恢复测试
日常的数据备份及恢复测试,是DBA工作重中之重的事情,所以要做好备份及测试,日常的备份常见有mysqldump+binlog备份.xtrabackup+binlog备份,无论那一种,几乎都少不了对bi ...
- jmeter csv中获取带引号的数据详情
最近在工作中,对jmeter实践的点滴的记录这里分享,不一定正确,仅供参考和讨论,有想法的欢迎留言.谈论. 1技巧1:从csv中获取带引号的数据详情 背景:我们从csv中获取数据,在jmeter中使用 ...
- 步步为营-86-WSFUpload组件
文件上传组件,所需js文件和图片在百度网盘对应的文件夹下 <%@ Page Language="C#" AutoEventWireup="true" Co ...
- OpenCV-Python入门教程2-打开摄像头
一.打开摄像头 import cv2 # 打开摄像头并灰度化显示 capture = cv2.VideoCapture(0) while(True): # 获取一帧 ret, frame = capt ...
- Nginx配置TCP请求转发
Nginx配置TCP请求转发 1.TCP请求转发基于stream在1.9版本前,需要单独编译安装该组建: # 依赖服务 [root@baolin conf]#yum -y install pcre-d ...
- MyBatis - 8.MyBatis工作原理
Mybatis 配置 1.SQLSessionFactory的初始化 根据配置文件获取 SqlSessionFactory 2.openSession获取SqlSession对象 3.getMappe ...