andieje
asked on
syntax error in shell script
Hi
There is a syntax error in the following shell script. I must have accidentally modified it as I didn't write it:
./check.sh: line 8: syntax error near unexpected token `done'
'/check.sh: line 8: ` done < CHECKSUMS
thanks for your help
There is a syntax error in the following shell script. I must have accidentally modified it as I didn't write it:
./check.sh: line 8: syntax error near unexpected token `done'
'/check.sh: line 8: ` done < CHECKSUMS
thanks for your help
while read sum blocks name
do
if [ "$sum" == "$(sum $name | cut -f1 -d" ")" ] ; then
echo sum of $name is correct!
else
echo sum of $name is incorrect!
fi
done < CHECKSUMS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you simply get rid of !
Or escape it
echo "\!"
Or escape it
echo "\!"
Looks like it is accepting [ ] as well or at least the version I am using. However ! is a problem
The problem is the file 'CHECKSUMS'
you are passing one line that is not in the expected format.
I'd take a stab in the dark that you have gained an extra linefeed on the end of the file. maybe by importing it from a windows machine.
This script seems to have been used on a few pages (most of which claim they wrote it). A quick google will show other people who have had similar issues.
Have a look at :
http://experts-answer.net/2011/01/25/shell_script___unexpected_operator/#more-8280
and go for changing line 3 to this (note the single quotes) :
if [ "$sum" == "$(sum $name | cut -f1 -d' ')" ] ; then
you are passing one line that is not in the expected format.
I'd take a stab in the dark that you have gained an extra linefeed on the end of the file. maybe by importing it from a windows machine.
This script seems to have been used on a few pages (most of which claim they wrote it). A quick google will show other people who have had similar issues.
Have a look at :
http://experts-answer.net/2011/01/25/shell_script___unexpected_operator/#more-8280
and go for changing line 3 to this (note the single quotes) :
if [ "$sum" == "$(sum $name | cut -f1 -d' ')" ] ; then
ASKER
the file checksums has been downloaded by ftp and unzipped. I've checked the file with a perl script which looks for non printing characters and it ends in a single \n
However i never though to check the script itself. It looks like i have given every line a carriage return and a line feed?
However i never though to check the script itself. It looks like i have given every line a carriage return and a line feed?
while read sum blocks name^M$
do^M$
if [ $sum -eq $(sum $name | cut -f1 -d" ") ] ; then^M$
echo sum of $name is correct!^M$
else^M$
echo sum of $name is incorrect!^M$
fi^M$
done < CHECKSUMS^M$
done < CHECKSUMSwhat is this?
you send CHECKSUMS into done O_o?
i more work with bash.. but i don't think that send chars into "done" is right thing..
btw if strange also, but let this part to SH scripters..
you send CHECKSUMS into done O_o?
i more work with bash.. but i don't think that send chars into "done" is right thing..
btw if strange also, but let this part to SH scripters..
ASKER
thanks again wmp for giving me the script initially and helping me find out how i had messed it up this time!
You transferred it via ftp without specifying "binary" transfer mode, right?
undersky
is the same as
cat file | while read line
do
...
done
is the same as
while read line
do
..
done <file
OR use eq instead of ==
Second, you cannot use ! without quoting it
You have to write
echo "sum of $name is correct!"