a.sh: command substitution: line 1: Syntax error near unexpected token `(' a.sh: command substitution: line 1: `comm -12 <( sort /home/xyz/a.csv1 | uniq) <( sort /home/abc/tempfile | uniq) | wc -l'
代码片段 –
temp=`comm -12 <( sort /home/xyz/a.csv1 | uniq) <( sort /home/abc/tempfile | uniq) | wc -l` echo $temp
解决方法
#!/bin/sh
或者您在测试时使用sh script.sh而不是bash script.sh,或者您在环境中设置了SHELL = / bin / sh或类似的东西.您的失败是在process substitution代码上.当Bash以sh运行时(在POSIX mode中),则进程替换不可用:
- Process substitution is not available.
你需要写:
#!/bin/bash temp=$(comm -12 <(sort -u /home/xyz/a.csv1) <(sort -u /home/abc/tempfile) | wc -l) echo $temp
甚至简单地说:
#!/bin/bash comm -12 <(sort -u /home/xyz/a.csv1) <(sort -u /home/abc/tempfile) | wc -l
这将获得与回声后跟随捕获相同的效果.测试时,使用bash -x script.sh或bash script.sh.
解读难以理解的评论
BASH=/bin/sh
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=([0]=”0″)
BASH_SOURCE=([0]=”a.sh”)
BASH_VERSINFO=([0]=”4″ [1]=”1″ [2]=”2″ [3]=”1″ [4]=”release” [5]=”x86_64-redhat-linux-gnu”)
BASH_VERSION=’4.1.2(1)-release’
CVS_RSH=ssh
SHELL=/bin/bash
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=2
请注意,BASH = / bin / sh和SHELLOPTS = braceexpand:hashall:interactive-comments:posix.这些中的任何一个或两个都可能是问题的主要部分.