format (rather than ${array[*]}) is used, and also that double quotes are put around the whole construct.
items=(pen "permanent marker" pencil "temporary marker")
for item in ${items[@]} do
echo "Item is : $item" done
Item is : pen
Item is : permanent
Item is : marker
Item is : pencil
Item is : temporary
Item is : marker
for item in ${items[*]} do
echo "Item is : $item" done
Item is : pen
Item is : permanent
Item is : marker
Item is : pencil
Item is : temporary
Item is : marker
items[@] and items[*] produced the same output and which is not expected. "permanent" and "marker" are treated as two different words in both the cases though it is a single word. lets try now with the quotes around the array..
items=(pen "permanent marker" pencil "temporary marker")
for item in "${items[@]}" do
echo "Item is : $item" done
Item is : pen
Item is : permanent marker
Item is : pencil
Item is : temporary marker
YES this what we expected.... but items[*] will not behave this way.
for item in "${items[*]}" do
echo "Item is : $item" done
Item is : pen permanent marker pencil temporary marker
the * is not suitable either with or without quotes. Without quotes, it does the same as the @ symbol. With quotes, the whole array is boiled down into a single string.
0 comments:
Post a Comment