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 token
in' ./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!
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.
Comments