Iterating over a list of tuples in bash

1 Comment
Posted 21 Jul 2010 in bash, linux

I’ve shown previously how to rename many files on the command line. That solution required a 2nd textfile in the format oldname<space>newname<return>.

Sometimes it is easier if there is no external file and we simply want to iterate over a list that is part of the script. The command to use in this case is called set, which will split on the character in the variable IFS (=internal field separator?).


for i in a,b c,d ; do IFS=","; set $i; echo $1 $2; done

Will output:

a b
c d


  1. Nice article, it was useful for me but I added “unset IFS; ” before the keyword “done”.


Add Your Comment