Syntax error near unexpected token 'done'
As it stands, your code is equivalent to:
for var in bent bound bled bred brought built burned burnt bought caught clung \ crept dealt dug dived dreamed dreamt fed felt fought found fled flung \ ground hung heard held kept knelt laid led leaped leapt learned learnt \ left lent lighted lost made meant met misspelled misspelt mowed mown \ paid pled proved proven sawed sawn said sought sold sent sewed sewn \ shaved shaven shone shoed shod shot showed sat slept slid slung sowed \ sown sped spent silted spilt spun sprung stood stuck stung struck \ strung swept swelled swollen swung taught told thought thrived \ understood upheld waved woven wept wound won withheld withstood wrung do cd ~ cd Documents/UPenn/'Senior Year'/'Spring 2011'/Thesis/Results/ echo "$var" NUMLINE=0 cat 'foradam.txt' | while IFS=$'\t' read -r word pos other; do if [ "$word" = '#' ] || [ "$word" = Number ] || [ "$word" = CHI ]; then NUMLINE=`expr $NUMLINE + 1` echo "error 1" echo "$word" echo "$NUMLINE" if [ "$word" = $var ] && [ "$pos" = VVN ];then sed -i '$NUMLINE' d Brown_Adam_CIVForms.txt echo "error 4" echo "$word" echo "$NUMLINE" else echo "nothing on this line" echo "$word" echo "$NUMLINE" fi fi # This fi is missing in your code!!! donedone
There is a 'fi
' missing, which makes the 'done
' unexpected. An alternative diagnosis is that the nested 'if
' should actually be an 'elif
':
for var in bent bound bled bred brought built burned burnt bought caught clung \ crept dealt dug dived dreamed dreamt fed felt fought found fled flung \ ground hung heard held kept knelt laid led leaped leapt learned learnt \ left lent lighted lost made meant met misspelled misspelt mowed mown \ paid pled proved proven sawed sawn said sought sold sent sewed sewn \ shaved shaven shone shoed shod shot showed sat slept slid slung sowed \ sown sped spent silted spilt spun sprung stood stuck stung struck \ strung swept swelled swollen swung taught told thought thrived \ understood upheld waved woven wept wound won withheld withstood wrung do cd ~ cd Documents/UPenn/'Senior Year'/'Spring 2011'/Thesis/Results/ echo "$var" NUMLINE=0 cat 'foradam.txt' | while IFS=$'\t' read -r word pos other; do if [ "$word" = '#' ] || [ "$word" = Number ] || [ "$word" = CHI ]; then NUMLINE=`expr $NUMLINE + 1` echo "error 1" echo "$word" echo "$NUMLINE" elif [ "$word" = $var ] && [ "$pos" = VVN ]; then sed -i '$NUMLINE' d Brown_Adam_CIVForms.txt echo "error 4" echo "$word" echo "$NUMLINE" else echo "nothing on this line" echo "$word" echo "$NUMLINE" fi donedone
Try putting the while loop in a subshell. Also, one of your if
statements is missing an elif
cat 'foradam.txt' | ( while IFS=$'\t' read -r word pos other; do if [ "$word" = '#' ] || [ "$word" = Number ] || [ "$word" = CHI ]; then ... elif [ "$word" = $var ] && [ "$pos" = VVN ]; then ... else ... fidone )
I looked at a for
/done
example and they showed it as:
#!/bin/bashfor i in $( ls ); do echo item: $idone
That is, only one done
at the end. You have two.