I am trying to read a variable with spaces on prompt and trying to use in a for loop.,
For example:
Enter the items to read separated by space...
apple orange kiwi
read items
for i in "$items"
do
echo $i
...(additional operations)....
done
But shell does take the first item - apple here. What am I missing here.
bash
? With what you have, I'd expect your loop to run once, and the value of$i
to be"apple orange kiwi"
. Try removing the quotes from"$items"
and see if that gets you closer to what you're expecting.