【问题标题】:How to combine command substitution and regex?如何结合命令替换和正则表达式?
【发布时间】:2013-06-16 00:09:05
【问题描述】:

是否有可能在正则表达式中进行命令替换? 我想在 Linux 中查找具有特定名称的文件。名称可能包含修复字符串,但也可能仅包含主机名。 所以我想做的是:

find /home/ -type f -regextype posix-extended -regex '.*(string1|string2|`hostname`).*'

我不确定是否有可能以某种方式将主机名命令的输出与正则表达式连接起来? 提前致谢!

【问题讨论】:

    标签: regex bash find command-substitution


    【解决方案1】:

    试试这个:

    find /home/ -type f -regextype posix-extended -regex ".*(string1|string2|$HOSTNAME).*"
    

    如果您需要使用命令:

    find /home/ -type f -regextype posix-extended -regex ".*(string1|string2|$(hostname)).*"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多