Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
Added some highlighting and tried to make the question more clear.
Source Link
Matt
  • 9.4k
  • 2
  • 29
  • 33

I want to use arrays in my sh script.

My target is to create an array with the values a b c and print all values in the array.

I succeeded to print each array, but I failed to print all values in the array.

Following example:

Set each value in arr:

n=1
eval arr$n=a
n=2
eval arr$n=b
n=3
eval arr$n=c

Print each value from arr:

n=1
eval echo \$arr$n
a
n=2
eval echo \$arr$n
b
n=3
eval echo \$arr$n
c

Now I want to print all values in $arr and instead of a b c I get:

n="*"
eval echo \$arr$n
{*}*

The values should be a b c.

I want to use arrays in my sh script.

My target is to create an array with the values a b c and print all values in the array.

I succeeded to print each array, but I failed to print all values in the array.

Following example:

Set each value in arr:

n=1
eval arr$n=a
n=2
eval arr$n=b
n=3
eval arr$n=c

Print each value from arr:

n=1
eval echo \$arr$n
a
n=2
eval echo \$arr$n
b
n=3
eval echo \$arr$n
c

Now I want to print all values in $arr and instead a b c I get:

n="*"
eval echo \$arr$n
{*}*

The values should be a b c.

I want to use arrays in my sh script.

My target is to create an array with the values a b c and print all values in the array.

I succeeded to print each array, but I failed to print all values in the array.

Following example:

Set each value in arr:

n=1
eval arr$n=a
n=2
eval arr$n=b
n=3
eval arr$n=c

Print each value from arr:

n=1
eval echo \$arr$n
a
n=2
eval echo \$arr$n
b
n=3
eval echo \$arr$n
c

Now I want to print all values in $arr and instead of a b c I get:

n="*"
eval echo \$arr$n
{*}*

The values should be a b c.

Added some highlighting and tried to make the question more clear.
Source Link

I want to use arrays in my sh script.

myMy target is to create an array for followingwith the values - a b c anda b c and print all values byin the array.

I successessucceeded to print each array  , but I failed to print all values in the array.

Please look on the followingFollowing example:

setSet each value in arr:

n=1
eval arr$n=a
n=2
eval arr$n=b
n=3
eval arr$n=c

printPrint each value from arr:

n=1
eval echo \$arr$n
a
n=2
eval echo \$arr$n
b
n=3
eval echo \$arr$n
c

nowNow I want to print all values with the $arr

in $arr and I get the following instead toa b c I get "a b c":

n="*"
 
eval echo \$arr$n
 
{*}*

theThe values should be: a b c.

a b c

I want to use arrays in my sh script

my target is to create array for following values - a b c and print all values by the array

I successes to print each array  , but I failed to print all values in the array

Please look on the following example

set each value in arr

n=1
eval arr$n=a
n=2
eval arr$n=b
n=3
eval arr$n=c

print each value from arr

n=1
eval echo \$arr$n
a
n=2
eval echo \$arr$n
b
n=3
eval echo \$arr$n
c

now I want to print all values with the $arr

and I get the following instead to get "a b c"

n="*"
 
eval echo \$arr$n
 
{*}*

the values should be:

a b c

I want to use arrays in my sh script.

My target is to create an array with the values a b c and print all values in the array.

I succeeded to print each array, but I failed to print all values in the array.

Following example:

Set each value in arr:

n=1
eval arr$n=a
n=2
eval arr$n=b
n=3
eval arr$n=c

Print each value from arr:

n=1
eval echo \$arr$n
a
n=2
eval echo \$arr$n
b
n=3
eval echo \$arr$n
c

Now I want to print all values in $arr and instead a b c I get:

n="*"
eval echo \$arr$n
{*}*

The values should be a b c.

Source Link
maihabunash
  • 7.2k
  • 22
  • 68
  • 80
Loading