Suppose I have a Unix shell variable as below
variable=abc,def,ghij
I want to extract all the values (abc
, def
and ghij
) using a for loop and pass each value into a procedure.
The script should allow extracting arbitrary number of comma-separated values from $variable
.
Not messing with IFS
Not calling external command
variable=abc,def,ghij
for i in ${variable//,/ }
do
# call your procedure/other scripts here below
echo "$i"
done
Using bash string manipulation http://www.tldp.org/LDP/abs/html/string-manipulation.html