msb65
1
Hi,
I have two bash shell scripts:
test:
rrdhcp78-120:test_data msb65$ cat ~/bin/test
#!/bin/sh
array1=()
echo 'elements in array1:' ${#array1[@]}
~/bin/test2 $array1
test2:
rrdhcp78-120:test_data msb65$ cat ~/bin/test2
#!/bin/sh
array2=${1}
echo 'elements in array2:' ${#array2[@]}
When I run test:
rrdhcp78-120:test_data msb65$ ~/bin/test
elements in array1: 0
elements in array2: 1
Why is it that "array1" initially has 0 elements, but when I export the variable to test2, assign it to variable "array2", it then has 1 element?
Ikon
2
Cleaning up to make eaiser to read:
test
array1=()
echo 'elements in array1:' ${#array1[@]}
~/bin/test2 $array1
test2
#!/bin/sh
array2=${1}
echo 'elements in array2:' ${#array2[@]}
When I run test:
rrdhcp78-120:test_data msb65$ ~/bin/test
elements in array1: 0
elements in array2: 1
Why is it that "array1" initially has 0 elements, but when I export the variable to test2, assign it to variable "array2", it then has 1 element?
Ikon
3
There is nothing in array1...
array1=()
Passing NULL?? maybe
~/bin/test2 $array1
Ikon
4
If your passing an array you will want this: (once there is something in it)
~/bin/test2 "$array1"
msb65
5
Hi,
Thanks for your help! However, that only seems to pass the first element of the array.
Ikon
6
~/bin/test2 "${array1[@]}"