Předání parametů v BASH

Marian Cavojsky cavo+konf na cavo.sk
Pátek Únor 8 08:05:25 CET 2008


On Thu, Feb 07, 2008 at 04:25:31PM +0100, "Petr \"Qaxi\" Klíma" wrote:
> Marian Cavojsky napsal(a):
> > On Thu, Feb 07, 2008 at 03:32:40PM +0100, "Petr \"Qaxi\" Klíma" wrote:
> >   
> >> Zdravím
> >> narazil jsem na potíž v Bashi
> >>
> >> ====== soubor ddate ==============================
> >>  #!/usr/bin/env bash
> >>
> >> set -x
> >>
> >> F='%a %e. %b %Y'
> >>
> >> # jak vygenerovat $CLI ?
> >> CLI="XXX"
> >>
> >> date $CLI "+${F}"
> >>     
> >
> > date "+${F}" $*


ok. Takze prejdeme na dalsiu polozku manualu:

$@
       @      Expands to the positional parameters, starting from one.
	      When the expansion occurs within double quotes, each
	      parameter expands to a separate word.  That is, "$@" is
	      equivalent to "$1" "$2" ...  If the double-quoted
	      expansion occurs within a word, the expansion of the first
	      parameter is joined with the beginning part of the
	      original word, and the expansion of the last parameter is
	      joined with the last part of the original word.  When
	      there are no positional parameters, "$@" and $@ expand to
	      nothing (i.e., they are removed).


$ cat bin/ddate 
#!/usr/bin/env bash

F='%a %e. %b %Y'
date "+${F}" "$@"

$ bash -x ddate -d "2 day ago"
+ F='%a %e. %b %Y'
+ date '+%a %e. %b %Y' -d '2 day ago'
St  6. feb 2008

$ bash -x ddate -r .bashrc 
+ F='%a %e. %b %Y'
+ date '+%a %e. %b %Y' -r .bashrc
So  8. dec 2007



Další informace o konferenci Linux