我的内容需要在两个变量中进行比较-- res1和res2
compRes=`diff -W999 --side-by-side <(echo ${res1}) <(echo ${res2})`抛出一些错误
command substitution: line 435: syntax error near unexpected token `('
command substitution: line 435: `diff -W999 --side-by-side <(echo ${res1}) <(echo ${res2})'也尝试过双引号。
compRes=`diff -W999 --side-by-side <(echo "$res1") <(echo "$res2")`同样的错误:
command substitution: line 435: syntax error near unexpected token `('
command substitution: line 435: `diff -W999 --side-by-side <(echo "$res1") <(echo "$res2")'有什么问题吗?
一些附加信息(奇怪):
File: test.sh
file1="Simple.csv"
file2="SimpleWithAddedLine.csv"
res1=$(cut -d, -f1-2 $file1)
res2=$(cut -d, -f1-2 $file2)
compRes=`diff -W999 --side-by-side <(echo "$res1") <(echo "$res2") | sed '/^[^\t]*\t\s*|\t\(.*\)/{s//\1 CMPUPDATED/;b};/^\([^\t]*\)\t*\s*<$/{s//\1 CMPDELETED/;b};/^.*>\t\(.*\)/{s//\1 CMPNEW/;b};d'`
added=$(echo "$compRes" | grep "CMPNEW" | wc -l)
deleted=$(echo "$compRes" | grep "CMPDELETED" | wc -l)
updated=$(echo "$compRes" | grep "CMPUPDATED" | wc -l)
let "ttlUpdates = $added + $deleted + $updated"
echo -e "\nAdded: $added - Deleted: $deleted - Updated: $updated"
echo -e "Total Changes: $ttlUpdates (Maximum allowed: $maxAllowed)\n"和
File: callscript.sh
#!/bin/bash
CORE_SCRIPT_FILE="test.sh"
sh ${CORE_SCRIPT_FILE} | tee "logfile.log"好吧,我有两个文件。当我打电话给test.sh的时候-一切都很好。
[batch]$ ./test.sh
Added: 4 - Deleted: 1 - Updated: 1
Total Changes: 6 (Maximum allowed: )同时,当我调用- callscript.sh文件时:
[batch]$ ./callscript.sh
/abc/test.sh: command substitution: line 6: syntax error near unexpected token `('
/abc/test.sh: command substitution: line 6: `diff -W999 --side-by-side <(echo "$res1") <(echo "$res2") | sed '/^[^\t]*\t\s*|\t\(.*\)/{s//\1 CMPUPDATED/;b};/^\([^\t]*\)\t*\s*<$/{s//\1 CMPDELETED/;b};/^.*>\t\(.*\)/{s//\1 CMPNEW/;b};d''发布于 2015-09-08 08:26:27
在callscript.sh中,当您运行test.sh时,您使用的是sh,但是<(...)进程替换语法仅在bash中。将最后一行更改为
bash ${CORE_SCRIPT_FILE} | tee "logfile.log"而且它应该能正常工作。
https://stackoverflow.com/questions/32450566
复制相似问题