linux - Shell - 失败时运行附加命令

标签 linux bash shell command pdf2swf

我目前正在运行这个脚本,它适用于除一个以外的所有实例:

 #!/bin/sh
 pdfopt test.pdf test.opt.pdf &>/dev/null
 pdf2swf test.opt.pdf test.swf
 [ "$?" -ne 0 ] && exit 2

在上面的代码之后要执行更多行......

如果“pdf2swf test.opt.pdf test.swf”失败,我该如何更改此脚本以运行“pdf2swf test.pdf test.swf”?如果第二次尝试失败,那么我将“exit 2”。

谢谢

最佳答案

短路“或”应该做你想做的:

pdf2swf test.opt.pdf test.swf || pdf2swf test.pdf test.swf

关于linux - Shell - 失败时运行附加命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2653483/

相关文章:

php - 使用脚本在一堆模板中查找函数调用

linux - 编译器的编译会影响编译后的程序吗?

bash - sed 替换 ' with\'

bash - Printf 使用 Bash 按空格分割字符串

bash - 如何在 git 别名(Windows 上的 git-bash)中转义上游的花括号 @{u}? [更新]

linux - BASH:- 将字符串解析为单独的命令行参数

linux - 我想用树莓派创建一个无线局域网,它将运行nodejsexpress框架来在浏览器中播放视频

linux - 如何判断 elf 文件的链接类型?

c - Linux 系统调用如何与文件系统交互

android - 在 Android 终端中运行 Python