Syntax error in while loop near unexpected token `in'

dia.duran

I want to process some data and I need to narrow the area to process by reading some coordinates written in a text file,..

I have the following error:

./script5.sh: line 59: syntax error near unexpected tokenin' ./script5.sh: line 59: while IFS="" read -r $L1Aname north south east west || [[ -n "$L1Aname north south east west" ]] in $coord; do'

This is what I have:

while IFS="" read -r $L1Aname north south east west || [[ -n "$L1Aname north south east west" ]] in $coord; do
    Nlat="$north"  #name variable north
    Slat="$south"  #name variable south
    Elon="$east"  #name variable east
    Wlon="$west" #name variable west
done < "$coord"; 

Thanks!

Kusalananda

Your while-loop looks, as Barmar points out in his comment to the question, as if it was originally a for-loop that iterated over $coord (a variable possibly holding the whole contents of a file).

The correct while-loop may look something like

while read -r L1Aname north south east west; do
    Nlat="$north"
    Slat="$south"
    Elon="$east"
    Wlon="$west"
done <"$coord"

I have also dropped the $ in $L1Aname. I'm not entirely sure this is correct though as you could read $L1Aname (this would read a value into the variable whose name is stored in the variable L1Aname). I will assume that this was unintentional though (just change L1Aname to $L1Aname below if I'm wrong).

If you need to check for non-empty values, don't test on the string "$L1Aname north south east west" as this is guaranteed to be non-empty. Instead, test the values of the individual variables:

while read -r L1Aname north south east west
    && [ -n "$north" ] && [ -n "$south" ]
    && [ -n "$east"  ] && [ -n "$west"  ]
do
    Nlat="$north"
    Slat="$south"
    Elon="$east"
    Wlon="$west"

    # use "$Nlat", "$Slat", "$Elon" and "$Wlon" here.

done <"$coord"

You don't need to test on $L1Aname as this is guaranteed to contain something if the read was able to read something.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

syntax error near unexpected token `echo'

From Dev

awk: syntax error near unexpected token `('

From Dev

bash: syntax error near unexpected token `('

From Dev

Syntax error near unexpected token 'then'

From Dev

syntax error near unexpected token `&' (using "|&")

From Dev

Bash syntax error near unexpected token `('

From Dev

sh: syntax error near unexpected token `}'

From Dev

Bash script: syntax error near unexpected token?

From Dev

Cron syntax error near unexpected token

From Dev

Fabric: syntax error near unexpected token '('

From Dev

syntax error near unexpected token `(' python script

From Dev

syntax error near unexpected token `}' `

From Dev

Syntax error near unexpected token `='()

From Dev

syntax error near unexpected token `<'

From Dev

syntax error near unexpected token `then'

From Dev

Syntax error near unexpected token `('

From Dev

bash: syntax error near unexpected token `('

From Dev

Syntax error near unexpected token `('

From Dev

Syntax error near unexpected token `('

From Dev

syntax error near unexpected token `<'

From Dev

syntax error near unexpected token `('

From Dev

syntax error near unexpected token `}'

From Dev

Syntax error near unexpected token '{'

From Dev

Syntax error near unexpected token `newline' while installing Predictionio

From Dev

Syntax error near unexpected token '('

From Dev

Syntax error near unexpected token '(' while trying to move files

From Dev

Syntax error near unexpected token "done"-- while read line

From Dev

syntax error near unexpected token `

From Dev

Syntax error near unexpected token `then'