我想下面的脚本中从两个不同的文件合并列:粘贴命令
#!/bin/sh
#
#
echo "1 1 1" > tmp1
echo "2 2 2" >> tmp1
echo "3 3 3" >> tmp1
echo "a,b,c" > tmp2
echo "a,b,c" >> tmp2
echo "a,b,c" >> tmp2
paste -d':' <(cut -d" " -f1 tmp1) <(cut -d"," -f 1-2 tmp2)
上述脚本工作正常,当我运行
bash test.sh
但是,它确实当我运行
sh test.sh
,我得到了以下错误消息不起作用
test.sh: line 13: syntax error near unexpected token `('
test.sh: line 13: `paste -d':' <(cut -d" " -f1 tmp1) <(cut -d"," -f 1-2 tmp2)'
有人可以解释这种行为的原因是什么?有没有解决它?谢谢。
['sh'](https://en.wikipedia.org/wiki/Bourne_shell)和['bash'](https://en.wikipedia.org/wiki/Bash_(Unix_shell))是单独的程序(尽管在某些系统中'sh'由于兼容性原因被指向'bash')。实际上没有理由使用'sh'。 – dimo414
@ dimo414当然,除非你正在编写一个能在任何符合POSIX标准的系统上工作的脚本,不管它是否安装了'bash'。 – chepner
@chepner因此“有效”:)但如果你的意图是编写一个Bash脚本,而不是试图支持每个可以调用的仅支持POSIX的环境,那么符合sh的顺序是一个不必要的麻烦。 – dimo414