Reputation: 1
I am trying to perform a simple for loop, but it keeps telling me there is a syntax error near do. I have tried to find some answers online, but nothing seems to be quite answering my question.
The for loop is as so. All it wants to do is find the differences between two folders:
#!/bin/bash
for word in $LIST; do
diff DIR1/config $word/config
done
exit
The syntax error is near do. It says "Syntax error near unexpected token 'do '". $LIST is set outside of this script by the program that calls it.
Does anyone know what might be happening here?
Upvotes: 0
Views: 3074
Reputation: 881193
That's certainly valid syntax for bash
so I'd be checking whether you may have special characters somewhere in the file, such as CR/LF at the ends of your lines.
Assuming you're on a UNIXy system, od -xcb scriptname.sh
should show you this.
In addition, you probably also want to use $word
rather than just word
since you'll want to evaluate the variable.
Another thing to check is that you are actually running this under bash
rather than some "lesser" shell. And it's often handy to place a set -x
within your script for debugging purposes as this outputs lines before executing them (use set +x
to turn this feature off).
One last thing to check is that LIST
is actually set to something, by doing echo "[$LIST]"
before the for
loop.
Upvotes: 3