【问题标题】:Shell comm parameters issueShell 通讯参数问题
【发布时间】:2015-06-25 15:45:22
【问题描述】:

我在运行带参数的 shell 脚本时遇到问题。 此命令直接在 Linux 上运行:

comm -13 <(sort /tmp/f1.txt) <(sort /tmp/f2.txt) > /tmp/f3.txt

如果我尝试使用这个发送参数的命令运行这个 shell 脚本,我会收到以下错误:

test.sh: line 6: syntax error near unexpected token `('
'est.sh: line 6: `comm -13 <(sort $1) <(sort $2) > $3

这是我的 shell 代码:

#!/bin/bash
comm -13 <(sort $1) <(sort $2) > $3

我使用以下命令运行它:

sh test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt

我想不出什么是错误的。 请帮忙。

谢谢你, -安德烈

【问题讨论】:

  • sh 不是 bash &lt;(...) 是 bash 功能。不要使用sh 来运行脚本。使用bash
  • 原因可能是您系统上的sh 意味着它不支持process substitution。为什么你把#!/bin/bash放在你的脚本里,用sh来执行呢?看到这个:gnu.org/software/bash/manual/html_node/…
  • 这行得通。非常感谢你们。

标签: linux shell comm


【解决方案1】:

解决方案:

  1. 既然你在脚本的shebang中指定了bash,为什么还要用sh来调用呢?只需运行./test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt

  2. 明确使用bashbash test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    • 2022-01-20
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多