Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When I run the code below:

IFS=$'\n'
for line in `more extensions.txt` do 
    if  grep '[219..223]' ${line:96:4} ; then
        ...
    else
        ...
    fi
done

I keep getting the error:

bash: syntax error near unexpected token 'if'

Help, anyone?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You're missing either a semicolon or a newline before do.

Both of the following scripts will work.


IFS=$'\n'
for line in `more extensions.txt` ; do
        if  grep '[219..223]' ${line:96:4} ; then
                echo "1"
        else
                echo "2"
        fi
done

IFS=$'\n'
for line in `more extensions.txt`
do
        if  grep '[219..223]' ${line:96:4} ; then
                echo "1"
        else
                echo "2"
        fi
done

Note: Your script is also missing a shebang. It's better practice to include one in the first line of your script.

This allows you to call your script using ./script.sh if the file's executable bit is set, in addition to sh script.sh or bash script.sh

share|improve this answer
    
Lol thanks. Deleted it somehow –  Buckocee Oct 11 '12 at 20:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.