I have been trying to find a solution to how to loop over words in a string but I am unable to find anything so I decided to ask here :)
Basically, so far I tried looping over these ways:
- One (not POSIX)
while read -r line; do
for token in "${line[@]}"; do
echo "* $token"
done
done
- Two
while read -r line; do
for token in $line}; do
echo "* $token"
done
done
- Three
while read -r line; do
for token in "${line}"; do
echo "* $token"
done
done
They all fail:
- #1 doesn't split
- #2 splits but also globs
- #3 doesn't split
And I can't find a solution, any idea how to do it?
I don't even care if it's POSIX at this point, thanks for the answers in advance