【问题标题】:execute commands with curly brackets on bash在 bash 上执行带大括号的命令
【发布时间】:2014-05-20 16:15:37
【问题描述】:

我想知道为什么以下命令在 Bash 中不起作用以及如何使它运行:

/etc/init.d/{httpd,nscd} status

谢谢

【问题讨论】:

  • 学习使用 cmd 行的set -vx 功能来查看 cmd 是如何执行的。您使用set +vx 将其关闭。祝你好运。

标签: bash curly-brackets


【解决方案1】:

您的命令不起作用,因为它会执行:

/etc/init.d/httpd /etc/init.d/nscd status

实现您想要的一种方法是使用循环:

for util in /etc/init.d/{httpd,nscd} ; do
  ${util} status
done

【讨论】:

    【解决方案2】:

    这不起作用,因为它只会扩展路径。 试试这个。

    $ echo  /etc/init.d/{httpd,nscd} status
    
    $ /etc/init.d/httpd /etc/init.d/nscd status
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-08
      • 2014-02-10
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-07
      相关资源
      最近更新 更多