Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Array question

$
0
0
I have attempted to create an array consisting of two items: #0 and #1.
I am able to print the two items corrctly:
Code:

arr=(hello "my name is")
echo ${arr[0]}
hello
echo ${arr[1]}
my name is

However, when I try to run a for loop to print both objects:
Code:

for i in ${arr[*]}
do
echo $i
done

I get:
Code:

hello
my
name
is

If there are two objects, why is the output on four lines? How do I loop on two lines?

My goal is to get:
Code:

hello
my name is


Viewing all articles
Browse latest Browse all 16232

Trending Articles