我想下面的腳本中從兩個不同的文件合併列:粘貼命令
#!/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