Jirka Zahradnik
Jirka Zahradnik

Reputation: 101

Bash for loop syntax error removing semicolon didnt do the trick

I am doing wrapper for editor and I have this error in part, where I am checking if the file was already edited in certain directory. The directories are stored in file in format: path//date//openCount. Double slash is delimiter because slash is one of only forbidden chars in name on unix-like systems.

/home/test//20150320//1
/home/d3ad/Documents/skola/2015_zima/ios/proj1/ads//20150320//1
/home/d3ad/Documents/skola/2015_zima/ios/proj1/backup.sh//20150320//1
/home/d3ad/Documents/skola/2015_zima/ios/proj1/asd//20150320//7
/home/d3ad/Documents/skola/2015_zima/ios/proj1/bs//20150320//9

code:

FILE="false"
DIR=$(readlink -f "${2}")
#check if a file was already edited in this directory
for LINE in $(grep -n -o "${DIR}/[^/]*" ${WEDI_RC}); do
    if[ -f "${LINE}" ]; then
        FILE="true"
    fi
done

error:

./wedi: Syntax error: "then" unexpected (expecting "done")

I have tried to remove semicolons, moved "do" and "then" to the next line but neither worked. Do you have any ideas? I am quite desperate since I have 1 for loop above and it works properly.

Thank you for your answers

Upvotes: 0

Views: 306

Answers (1)

AdrieanKhisbe
AdrieanKhisbe

Reputation: 4058

You have a missing space between the if and the [ hence the syntax error.

if [ -f "${LINE}" ]; then # add missing space
    FILE="true"
fi

Upvotes: 2

Related Questions