I dont get it right, i always display only the first one, and i dont know how to write a scalar variable. I tried like this : ssh [EMAIL PROTECTED] script2 -f "[EMAIL PROTECTED]"
It's not changing anything. I m using bash. Thank you. Stephane Chazelas wrote: > > On Tue, Dec 09, 2008 at 09:14:51AM -0500, Chet Ramey wrote: >> > >> > Hello i would like to pass an array to my script command line argument, >> but >> > only the first element of the array is displayed. Here is my process : >> > >> > script1: >> > my_array=(el1 el2 el3) >> > script2 -f $my_array >> >> You're only passing the first element of the array to script2. An >> unsubscripted word expansion expands to the first element of an array. > [...] > > More exactly, an unsubscripted word expansion expands to the > element of subscript 0 or to the empty string if that element is > not defined. > > After > > a[12]=foo > > The first element is "foo", but $a expands to the empty string. > > $a is a shortcut for ${a[0]} and a=bar is a shortcut for a[0]=bar > > This is similar to ksh but different from zsh where arrays and > scalars are of different types, and arrays are not scarse arrays > but normal arrays. In zsh, a[12]=foo allocates an array of 12 > elements, the first 11 being empty; $a is the same as $a[*] and > is the list of non-empty elements in $a. Doing a=foo, would > change the type of $a to be a scalar, so you'd lose all the > array elements. The OP's code is actually zsh (or rc/es) syntax, > though it would make more sense to do: > > scalar -f "[EMAIL PROTECTED]" > > which would work the same in bash, ksh93 and zsh (and in zsh, it > wouldn't discard the empty elements, contrary to $my_array). > > -- > Stéphane > > > > -- View this message in context: http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20918475.html Sent from the Gnu - Bash mailing list archive at Nabble.com.