Sample Header Ad - 728x90

changing IFS temporarily before a for loop

8 votes
2 answers
4810 views
I know that the SHELL allows variable assignment to take place immediately before a command, such that IFS=":" read a b c d <<< "$here_string" works... What I was wondering is do such assignments not work when done with compound statements such as loops? I tried something like IFS=":" for i in $PATH; do echo $i; done but it results in a syntax error. I could always do something like oldIFS="$IFS"; IFS=":"; for....; IFS="$oldIFS", but I wanted to know if there was any way I could make such inline assignments work for compound statements like for loops?
Asked by computronium (878 rep)
Aug 16, 2020, 01:32 PM
Last activity: Mar 16, 2021, 07:02 PM