Skip to content
Advertisement

split for words separated with semicolon

I have some string like

1;2;3;4;5

I want to be able to iterate over this string taking each word one by one. For the first iteration to take 1 the next to take 2 and the last 5.

I want to have something like this

for i in $(myVar)
do
echo $i
done

but I do not know how to fill the myvar

Advertisement

Answer

echo '1;2;3;4;5' | tr ; \n | while read line ; do echo $line; done
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement