I have a list of values, separated by ':' and I want to process them one by one.
When the delimiter is space, there are no problems:
nuclear@korhal:~$ for a in 720 500 560 130; do echo $a; done
720
500
560
130
But after settings IFS (Internal Field Separator) to : , strange things start to happen:
nuclear@korhal:~$ IFS=":" for a in 720:500:560:130; do echo $a; done;
bash: syntax error near unexpected token `do'
If I skip all semicolons, when IFS is set:
nuclear@korhal:~$ IFS=":" for a in 720:500:560:130 do echo $a done;
Command 'for' not found, did you mean:
command 'vor' from deb vor (0.5.8-1)
command 'fop' from deb fop (1:2.5-1)
command 'tor' from deb tor (0.4.4.5-1)
command 'forw' from deb mailutils-mh (1:3.9-3.2)
command 'forw' from deb mmh (0.4-2)
command 'forw' from deb nmh (1.7.1-7)
command 'sor' from deb pccts (1.33MR33-6build1)
command 'form' from deb form (4.2.1+git20200217-1)
command 'fox' from deb objcryst-fox (1.9.6.0-2.2)
command 'fort' from deb fort-validator (1.4.0-1)
command 'oor' from deb openoverlayrouter (1.3.0+ds1-3)
Try: sudo apt install <deb name>
Bash does not recognize the for command at all. If there was no IFS set in this case, it will show the prompt, because it expects more output (normal behaviour)
What is happening when the IFS is set to custom character? Why the for loop does not work with it?
I am using Kubuntu 20.10 Bash version 5.0.17
done
. Setting IFS to" :"
generated your original error again. – berndbausch Mar 16 '21 at 11:47