i'm reading a few variables from a file using
while read a b c; do
(something)
done < filename
is there an elegant way to skip a variable (read in an empty value), i.e. if I want a=1 b= c=3, what should I write in the file?
Right now i'm putting
1 "" 3
and then use
b=$(echo $b | tr -d \" )
but this is pretty cumbersome, IMHO
any ideas?
With a blank field:
You can do:
If your data is comma delimited, you can also do:
(but you'll have problems if your fields contain commas, as you may in your current version if they contain quotes):
Also, in your version instead of using
tr
, you can do:but you can eliminate that step altogether using the following with your current data format:
however, comma-delimited fields is a more common format.
I am not sure if I understood what you want but you can skip certain values of the iteration (be it while, for or whatever) with continue and even stop the iteration with break