Shell 通讯参数问题
Shell comm parameters issue
我有一个问题 运行使用参数设置 shell 脚本。
此命令 运行ning 直接在 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 ) <(sort ) >
这是我的 shell 代码:
#!/bin/bash
comm -13 <(sort ) <(sort ) >
我运行它用下面的命令:
sh test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt
我 运行 不知道哪里出了问题。
请协助。
谢谢,
-安德烈
解决方案:
既然你在脚本的shebang
中指定了bash
,为什么还要用sh
来调用呢?干脆 运行 ./test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt
明确使用bash
:bash test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt
我有一个问题 运行使用参数设置 shell 脚本。 此命令 运行ning 直接在 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 ) <(sort ) >
这是我的 shell 代码:
#!/bin/bash
comm -13 <(sort ) <(sort ) >
我运行它用下面的命令:
sh test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt
我 运行 不知道哪里出了问题。 请协助。
谢谢, -安德烈
解决方案:
既然你在脚本的
shebang
中指定了bash
,为什么还要用sh
来调用呢?干脆 运行./test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt
明确使用
bash
:bash test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt