繁体   English   中英

如何从单个测试中执行两个 BASH shell 命令?

[英]How to execute two BASH shell commands from a single test?

为什么这不起作用?

test $? -eq 1 || $(echo "hello"; echo "hi")

我收到以下错误:

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.

您正在寻找3.2.5.3 分组命令

test $? -eq 1 || { echo "hello"; echo "hi"; }

大括号周围的空格和结尾的分号(或换行符)是必需的。


但是,不要用$? 变量(很容易不小心在其中插入另一个命令)

直接使用命令

some command here && { echo hello; echo hi; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM