【问题标题】:Running a perl command in a bash script on OSX在 OSX 上的 bash 脚本中运行 perl 命令
【发布时间】:2013-12-25 12:00:57
【问题描述】:

好的菜鸟问题在这里。

我在运行 perl 命令的 mac 上有一个 bash 脚本。更具体地说,我想在文本变量上运行以下内容

...

mytext=...

...

perl -pe 's/-\K(\w)/\U$1/g' ${mytext}

但我只是得到 -

Can't open perl script "mytextis": No such file or directory

有什么想法吗?

【问题讨论】:

    标签: macos perl bash


    【解决方案1】:

    这样做:

    perl -pe 's/-\K(\w)/\U$1/g' <<< ${mytext}
    

    这样${mytext} 的内容被用作perl 脚本的标准输入,否则shell 将其视为命令行参数,然后perl 将其视为文件名以从中读取脚本。

    &lt;&lt;&lt;Here 字符串,是 Here Documents 的变体。您可以在 Here Strings 部分中的 man bash 中了解它。

    【讨论】:

      猜你喜欢
      • 2014-03-24
      • 2013-07-11
      • 2015-11-28
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      相关资源
      最近更新 更多