next | next | up | down | Inhalt | Uebungen | Complete | Kommentar

all, section 6.4.

6.4.  Textersatz für Kommandos

Ein Kommando in `...` wird durch seine Standard-Ausgabe ersetzt. Zeilentrenner am Schluß werden entfernt:

$ echo `hostname` hat `who | wc -l` Benutzer
next hat 2 Benutzer
$ echo linux hat "`rsh linux who | wc -l`" Benutzer
linux hat       1 Benutzer

Kommandos werden auch innerhalb von "..." ersetzt, wobei dann nur ein Argument als Resultat entsteht. Sonst wird die Ausgabe an den Zeichen in Worte zerlegt, die in IFS stehen, wobei zusätzlich gilt

... IFS Internal field separators, normally space, tab, and newline. IFS is ignored if sh is running as root or if the effective user id differs from the real user id. ...

$ IFS=:
$ echo `ypcat passwd | grep bischof | grep H`
bischof 9Y.UyH7/PzuOY 106 11 Hans-Peter Bischof /home/bischof /usr/local/gnu/bin/bash

Allgemein schützen '...' und "..." vor Nachzerlegung an IFS.

$ echo "`ypcat passwd | grep bischof | grep H`"
bischof:9Y.UyH7/PzuOY:106:11:Hans-Peter Bischof:/home/bischof:/usr/local/gnu/bin/bash

Ungeschützte Argumente, Variablenwerte und Kommando-Ausgabe werden nachzerlegt, Dateinamen aber nicht:

$ IFS=:
$ echo hello > a:b; ls            
a:b
$ x='c:d'; echo * $x e:f "$x" `echo '1:2'` "`echo '3:4'`"
a:b c d e f c:d 1 2 3:4

Innerhalb von `...` wird \ zweimal bearbeitet:

$ a='echo `date`'
$ $a	`date`
$ echo $a	
$ `echo $a`
$ `echo \$a`
$ `echo \\$a`
$ `echo \\\$a`
$ `echo \\\\$a`
$ a='eval echo `$a`'
$ $a

Das letzte Beispiel ist eine endlose Schleife...

Man kann `...` schachteln, wenn man die innere Gruppe mit \ schützt:

$ echo Tag: `set `date`; echo $2`
Tag: 21


back | next | up | down | Inhalt | Uebungen | Complete | Kommentar


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1997).

Last modified 03/July/97