passing array to command line argument.
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 script2: while getopts ":f:" opt ; do case $opt in f ) arr="$OPTARG" ;; esac done echo "arr : [EMAIL PROTECTED]" -- View this message in context: http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20914576.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: passing array to command line argument.
Hello, So how can i pass the entire array, i m new to shell scripting so i do not really understand when you talk about unsubscripted word expansion Thank you for helping. 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. > > Chet > > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > > Chet Ramey, ITS, CWRU[EMAIL PROTECTED] > http://tiswww.tis.case.edu/~chet/ > > > > -- View this message in context: http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20915715.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: passing array to command line argument.
I did the change but i still have only the first element displaying. I must say that i m using ssh to call script2 on remote server so maybe it is the problem : script1 ssh [EMAIL PROTECTED] script2 -f [EMAIL PROTECTED] -d [EMAIL PROTECTED] and on script2 it only echoes the first element of both arrays. Chet Ramey wrote: > > Dolphin06 wrote: >> Hello, >> So how can i pass the entire array, i m new to shell scripting so i do >> not >> really understand when you talk about unsubscripted word expansion > > Since programs only take a list of strings as arguments, you have to > expand > the array to a list of values. The "[EMAIL PROTECTED]" expansion can do that. > Expanding an array variable without using a subscript (${array} as opposed > to ${array[subscript]}) expands to the first element. > > Chet > > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > > Chet Ramey, ITS, CWRU[EMAIL PROTECTED] > http://cnswww.cns.cwru.edu/~chet/ > > > > -- View this message in context: http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20916101.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: passing array to command line argument.
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.
how to know if a command was successful on remote server
Hello i m sending command to remote server, in my script on my local machine. I would like to know how can i return a value if the command on the remote server failed. on my script on local machine : #! /bin/bash #how can i get a returned value from this ? ssh [EMAIL PROTECTED] remotescript param Thank you. -- View this message in context: http://www.nabble.com/how-to-know-if-a-command-was-successful-on-remote-server-tp20939147p20939147.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
command not found on remote server
Hello all, Some script on the remote server are called in .bash_profile, so they are accessible for the user. But when i send a command via ssh, and that my command call those script, it says command unknown... What can i do for it to work ? Thank you. -- View this message in context: http://www.nabble.com/command-not-found-on-remote-server-tp20953229p20953229.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: command not found on remote server
Can i do something like this : ssh [EMAIL PROTECTED] export PATH=$PATH:/other path/ ; script param right ? Chet Ramey wrote: > > Dolphin06 wrote: >> Hello all, >> >> Some script on the remote server are called in .bash_profile, so they are >> accessible for the user. But when i send a command via ssh, and that my >> command call those script, it says command unknown... >> What can i do for it to work ? > > Either change your command to have the necessary directories in $PATH or > call the scripts by their full pathnames. > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > > Chet Ramey, ITS, CWRU[EMAIL PROTECTED] > http://cnswww.cns.cwru.edu/~chet/ > > > > -- View this message in context: http://www.nabble.com/command-not-found-on-remote-server-tp20953229p20956977.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Formating variable with caracter and date.
Hello all, I would like to give a variable a value which have a format like this one: <3 letters>-- should be yymmdd. Date of the day by default. How would i do this, i know the date command is date +"%y-%m-%d", but i dont know the syntax for mixing letters date and digit into one variable. Also i would like to give the user a chance to change this default value, by letting him enter one, so i would like to know how can i check if the entered value is in the correct format. Thank you for helping. -- View this message in context: http://www.nabble.com/Formating-variable-with-caracter-and-date.-tp20973500p20973500.html Sent from the Gnu - Bash mailing list archive at Nabble.com.