Prev: Processing 100 output files
Next: Useful use of cat? (was Re: This Week's Useless Use of Cat Awardgoes to...)
From: Tobias Nissen on 24 Feb 2010 10:10 Dominic Fandrey wrote: > On 24/02/2010 15:50, Tobias Nissen wrote: >> Janis wrote: >>> On 24 Feb., 15:30, Tobias Nissen <t...(a)movb.de> wrote: >>>> How can I retain the quotes? >>> >>> Use double quotes around variable expansions. >> >> Sorry, I don't get what you mean. > > command "$@" Aah, OK. So the quotes got lost because of my args="$@" ... kd-$command $args # or "$args" ... doesn't matter Thank you both!
From: Mart Frauenlob on 24 Feb 2010 17:26 On 24.02.2010 16:10, Tobias Nissen wrote: > Dominic Fandrey wrote: >> On 24/02/2010 15:50, Tobias Nissen wrote: >>> Janis wrote: >>>> On 24 Feb., 15:30, Tobias Nissen <t...(a)movb.de> wrote: >>>>> How can I retain the quotes? >>>> >>>> Use double quotes around variable expansions. >>> >>> Sorry, I don't get what you mean. >> >> command "$@" > > Aah, OK. So the quotes got lost because of my > > args="$@" > ... > kd-$command $args # or "$args" ... doesn't matter > > Thank you both! It does matter! An unquoted variable undergoes word splitting. args="foo bar" some_command $args <-- results in 2 arguments passed to some_command. some_command "$args" <-- results in 1 argument passed to some_command. Best regards Mart
From: Mart Frauenlob on 24 Feb 2010 17:29 On 24.02.2010 16:10, Tobias Nissen wrote: > Dominic Fandrey wrote: >> On 24/02/2010 15:50, Tobias Nissen wrote: >>> Janis wrote: >>>> On 24 Feb., 15:30, Tobias Nissen <t...(a)movb.de> wrote: >>>>> How can I retain the quotes? >>>> >>>> Use double quotes around variable expansions. >>> >>> Sorry, I don't get what you mean. >> >> command "$@" > > Aah, OK. So the quotes got lost because of my > > args="$@" > ... > kd-$command $args # or "$args" ... doesn't matter > > Thank you both! forgot to say: the quoted "$@" variable is special. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... Best regards Mart
From: Tobias Nissen on 25 Feb 2010 02:39 Mart Frauenlob wrote: > On 24.02.2010 16:10, Tobias Nissen wrote: >> Dominic Fandrey wrote: >>> On 24/02/2010 15:50, Tobias Nissen wrote: >>>> Janis wrote: >>>>> On 24 Feb., 15:30, Tobias Nissen <t...(a)movb.de> wrote: >>>>>> How can I retain the quotes? >>>>> >>>>> Use double quotes around variable expansions. >>>> >>>> Sorry, I don't get what you mean. >>> >>> command "$@" >> >> Aah, OK. So the quotes got lost because of my >> >> args="$@" >> ... >> kd-$command $args # or "$args" ... doesn't matter >> >> Thank you both! > > It does matter! > > An unquoted variable undergoes word splitting. Sure, but I meant it like "in my specific case it doesn't matter". I want a call like kd cmd arg1 -o "oarg1 oarg2" arg2 to translate into kd-cmd arg1 -o "oarg1 oarg2" arg2 But with the `args="$@"` approach I get kd-cmd arg1 -o oarg1 oarg2 arg2 # without the quotes around $args or kd-cmd "arg1 -o oarg1 oarg2 arg2" # with the quotes around $args both not satisfying :-) But using "$@$ directly works perfectly, thanks again!
First
|
Prev
|
Pages: 1 2 Prev: Processing 100 output files Next: Useful use of cat? (was Re: This Week's Useless Use of Cat Awardgoes to...) |