shell脚本中进程替换报错问题解决

脚本文件:netdata-installer.sh

脚本代码:

export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

uniquepath() {

local path=""

while read

do

if [[ ! "${path}" =~ (^|:)"${REPLY}"(:|$) ]]

then

[ ! -z "${path}" ] && path="${path}:"

path="${path}${REPLY}"

fi

done < <(echo "${PATH}" | tr ":" "\n")


[ ! -z "${path}" ] && [[ "${PATH}" =~ /bin ]] && [[ "${PATH}" =~ /sbin ]] && export PATH="${path}"

}

uniquepath

现象:

1,脚本文件权限-rwxr-xr-x.

2,执行脚本方法:sh /root/netdata/netdata-installer.sh

3,报错:

[root@localhost netdata]# sh ./netdata-installer.sh

./netdata-installer.sh: line 15: syntax error near unexpected token `<'

./netdata-installer.sh: line 15: ` done < <(echo "${PATH}" | tr ":" "\n")'

解决办法:

改变执行脚本的方法:

source /root/netdata/netdata-installer.sh

OK!问题解决

你可能感兴趣的:(Shell)