[英]How to execute two BASH shell commands from a single test?
Why does this not work?为什么这不起作用?
test $? -eq 1 || $(echo "hello"; echo "hi")
I get the following error:我收到以下错误:
Command 'hello' not found, but can be installed with:
snap install hello # version 2.10, or
apt install hello # version 2.10-2ubuntu4
apt install hello-traditional # version 2.10-5
See 'snap info hello' for additional versions.
You're looking for 3.2.5.3 Grouping Commands您正在寻找3.2.5.3 分组命令
test $? -eq 1 || { echo "hello"; echo "hi"; }
The spaces around the braces and the trailing semicolon (or newline) are required.大括号周围的空格和结尾的分号(或换行符)是必需的。
However, don't test the exit status with the $?
但是,不要用
$?
variable (it's too easy to accidentally insert another command in there)变量(很容易不小心在其中插入另一个命令)
Use the command directly直接使用命令
some command here && { echo hello; echo hi; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.