Suppose I have a Unix shell variable as below
I want to extract all the values (
ghij) using a for loop and pass each value into a procedure.
The script should allow extracting arbitrary number of comma-separated values from
You can use the following script to dynamically traverse through your variable, no matter how many fields it has as long as it is only comma separated.
for i in $(echo $variable | sed "s/,/ /g")
# call your procedure/other scripts here below
Instead of the
echo "$i" call above, between the
done inside the for loop, you can invoke your procedure
Update: The above snippet works if the value of variable does not contain spaces. If you have such a requirement, please use one of the solutions that can change
IFS and then parse your variable.