Unix ksh:意外标记“done';
我正在尝试编写一个脚本,将满足特定条件的输出行写入一个新的.txt文件,尝试将unix和awk结合起来 一直在谷歌上搜索,但不断出现此错误:意外标记“完成”附近出现语法错误Unix ksh:意外标记“done';,unix,awk,ksh,Unix,Awk,Ksh,我正在尝试编写一个脚本,将满足特定条件的输出行写入一个新的.txt文件,尝试将unix和awk结合起来 一直在谷歌上搜索,但不断出现此错误:意外标记“完成”附近出现语法错误 Filename="bishan" file="659.A" while IFS= read line do cat $Filename.txt | awk '{ otherSubNo = substr($0,73,100);gsub(/ /,"",otherSubNo); if(length(other
Filename="bishan"
file="659.A"
while IFS= read line
do
cat $Filename.txt | awk '{ otherSubNo = substr($0,73,100);gsub(/
/,"",otherSubNo); if(length(otherSubNo)>8){ print "Subscriber Number is
",": ",substr($0,1,20)," Other Subscriber Number is ", " :
",substr($0,73,100) }}'| wc -l >> $Filename.txt
done <"$file"
01110000 00000000000000000000 6598540021 0101000000000006596197778001010000
000000 659854000300000000000000000000000000 004700001
请帮忙,我一直在谷歌上搜索这个问题,但没有用我能够重现指定的错误,尽管只是近似地重现,方法是在记事本(windows)中键入脚本,然后在cygwin中进行测试 script.sh:
while read myline
do
echo $myline
done
在ksh中:
~> /usr/bin/ksh ./script.sh
: not found
./script.sh[7]: syntax error: 'done' unexpected
在bash中:
~> /usr/bin/bash ./script.sh
./script.sh: line 2: $'\r': command not found
./script.sh: line 6: syntax error near unexpected token `done'
./script.sh: line 6: `done'
上述错误(至少在我的例子中)是由CRLF字符引起的。当我将代码复制粘贴到cygwin时,CRLF将变为LF(以及所有丢失的不可见控制字符),从而使错误消失。我无法重现症状。这就是整个剧本吗?你没有
#代码>顶行?是的,我有这顶行/bin/ksh当您需要更新问题以显示显示问题的整个复制和粘贴脚本时。同时显示准确的复制和粘贴错误消息。由于您不知道是什么导致了问题,根据定义,您不知道可以安全地忽略哪些信息(如#!
行)——因此不要忽略任何内容。如果您的脚本太大,请将其缩小,但请确保您发布的脚本确实存在问题。我看不出有错误,但您的代码格式太差,很难修改tell@glennjackman:我复制并粘贴代码,并在我的系统上运行它。错误没有发生。错误一定在别处。
~> /usr/bin/bash ./script.sh
./script.sh: line 2: $'\r': command not found
./script.sh: line 6: syntax error near unexpected token `done'
./script.sh: line 6: `done'