0

我在运行带有参数的 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

这是我的外壳代码:

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

我使用以下命令运行它:

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

我已经没有想法可能出了什么问题。请协助。

谢谢你,-安德烈

4

1 回答 1

1

解决方案:

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

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

于 2015-06-25T15:49:07.813 回答