Re: shell: promena v nazvu promene
To |
czdebian-l zavinac debian bod cz |
From |
Hans Ginzel <hans zavinac kolej bod mff bod cuni bod cz> |
Date |
Fri, 16 Jan 2004 10:48:23 +0100 |
Mail-followup-to |
czdebian-l zavinac debian bod cz |
User-agent |
Mutt/1.5.4i |
On Thu, Jan 15, 2004 at 06:03:31PM +0100, Jiří Jánský wrote:
> promena_jedna="ahoj"
> poradi="jedna"
> echo "$promena_`$poradi`" - a to by melo misto $poradi dosadit jedna
> a echo vypsat obsah promene $promena_jedna, tedy vypsat na "ahoj".
eval echo "\${promena_$poradi}"
eval [arg ...] The args are read and concatenated together into
a single command. This command is then read and executed by the shell,
and its exit status is returned as the value of eval.
Prikaz eval sputi (expandovane) parametry znovu jako prikaz shellu
(vcetne dalsi expanze). Tj. v prvnim kole se expanduje promena $poradi,
nebot druhy dolar neni escapovany:
echo ${promenna_jedna}
Slozene zavorky pouzivam preventivne, nebot si obsahem promenne $poradi
nemuzu byt jisty.
> To souvisi s mim zmatekm mezi znaky "", '' a`` moje nynejsi predstavy jsou:
> "" - zajisti, aby se retezec nerozdelil, pokud obsahuje mezere
Krome word splitting zabrani dalsi expanzi (historie, brace, tilde,
arithmetic,...)
Enclosing characters in double quotes preserves the literal value
of all characters within the quotes, with the exception of $, `, and \.
The characters $ and ` retain their special meaning within double
quotes. The backslash retains its special meaning only when followed
by one of the following characters: $, `, ", \, or <newline>. A dou-
ble quote may be quoted within double quotes by preceding it with a
backslash.
> '' - nemam totalni tuseni, k cemu to muze byt dobre
Apostrofy zabrani jakekoli expanzi, viz. man bash sekce QUOTING:
Enclosing characters in single quotes preserves the literal value
of each character within the quotes. A single quote may not occur
between single quotes, even when preceded by a backslash.
> `` - misto tech uvozovek(apostrofu) dosadi vystup z prikazu, ktery je v nem
> uveden
Casto se take hodi "`prikaz`", aby vylsedek byl jedno slovo.
> Kdyby mi někdo napsal, jak vyresit ty promene (pripadne poslal link),
> a/nebo objasnil ty zmatky v uvozovkach, byl bych vdecny. Sice jsem se
Prelozil uz nekdo ``man bash''? Nebo Bash Bash-Prog-Intro-HOWTO.gz?
Ci jina skola shellu v cestine?
Zdravi
Hans
--
Perl won the Linux Journal Editors' Choice Award :-)
http://www.linuxjournal.com/article.php?sid=6868
VIM is the Favorite Text Editor
(Linux Journal Readers' Choice Awards) :-)
http://www.linuxjournal.com/article.php?sid=7029
http://www.vim.org/sponsor/
Partial thread listing: