Předání parametů v BASH
Marian Cavojsky
cavo+konf na cavo.sk
Čtvrtek Únor 7 15:57:30 CET 2008
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}" $*
> ==============================================
>
> chci dosahnout toho aby fungovalo
> $ ddate
> Čt 7. úno 2008
>
> i
> $ ddate -d "2 day ago"
> Út 5. úno 2008
>
> i
> $ ddate -r /etc/passwd
> St 31. říj 2007
>
>
> v zásadě potřebuji vzít parametry ddate a předat je programu date
>
> Musím to udělat pomocí
> case $1
> -d) ....
>
> nebo to jde nějak obecněji?
inak na toto sa skor hodi alias:
$ alias dddate='date "+%a %e. %b %Y"'
$ dddate
Št 7. feb 2008
$ dddate -r /etc/passwd
Št 31. jan 2008
man bash
cast
Special Parameters
The shell treats several parameters specially. These
parameters may only be referenced; assignment to them is not
allowed.
* Expands to the positional parameters, starting
from one. When the expansion occurs within
double quotes, it expands to a single word with
the value of each parameter separated by the
first character of the IFS special variable.
That is, "$*" is equivalent to "$1c$2c...",
where c is the first character of the value of
the IFS variable. If IFS is unset, the parame-
ters are separated by spaces. If IFS is null,
the parameters are joined without intervening
separators.
--
Marian
Další informace o konferenci Linux