Am Die, 16 Apr 2002 schrieb David Haller:
Hallo,
On Mon, 15 Apr 2002, Christoph Maurer wrote:
Am Mon, 15 Apr 2002 schrieb Bernd Brodesser:
* David Haller schrieb am 15.Apr.2002:
etwas nicht schon (genau!) kennst, such in der manpage, lese das dann durch, verstehe es, probiere es aus, teste, spiel damit rum, usw...
Als Anregung/Uebung (*eg*):
a) Erklaere (im Detail) was die folgende Zeile macht und finde einen passenden Namen fuer 'x':
x() { echo "'${1/##*\/}' in '${1%\/*}'"; }
Muß das nicht entweder echo "'${1##*\/}' in ... oder aber echo "'${1/#*\//}' in ... heißen? Wobei bei letzterem Vorschlag der dritte Slash wegfallen kann.
Nein. Das Ergebnis waere ein anderes. War schon Absicht ;)
Und was ist dann ${1/##*\/} Ich zitiere mal die relevanten Teile von man bash ${parameter##word} The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``#'' case) or the longest matching pattern (the ``##'' case) deleted. If parameter is @ or *, the pattern removal operation is applied to each posi tional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal opera tion is applied to each member of the array in turn, and the expansion is the resultant list. ${parameter/pattern/string} ${parameter//pattern/string} The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. In the first form, only the first match is replaced. The second form causes all matches of pattern to be replaced with string. If pattern begins with #, it must match at the beginning of the expanded value of parameter. If pattern begins with %, it must match at the end of the expanded value of parameter. If string is null, matches of pattern are deleted and the / fol lowing pattern may be omitted. If parameter is @ or *, the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array vari able subscripted with @ or *, the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list. Das heißt ${1##*\/} schneidet von $1 ab dem Anfang das längste mögliche */ Muster ab(##), sprich, den kompletten Pfadnamen (basename) ${1/#*\/} macht das gleiche, nur das bei Patternsearch automatisch der längste Match ersetzt wird, # bedeutet hier, daß der Match von Anfang an stattfinden muss. Dein Vorschlag ${1/##*\/} bedeutet jedoch IMHO, daß das Suchmuster um es mal in Regex-Syntax zu schreiben ^#.*/ ist, oder was sehe ich falsch. Bei der Syntax ${parameter/pattern gibt es bei pattern nicht die Sonderbedeutung ##. Dein Beispiel führt nämlich auch, abgespeichert z.B. unter /home/ma/tmp/testscript und auch so aufgerufen zur Ausgabe '/home/ma/tmp/testscript' in '/home/ma/tmp' Dazu brauchst Du die ganze Parameter Substitution nicht, da hätte es auch echo "'$1' in ${1%\/*}'" getan. Mein Vorschlag führt hingegen zu 'testscript' in '/home/ma/tmp' was doch wohl eher beabsichtigt war.
Ahja, das mit den '...' ist klar, es steht innerhalb von "..." ok.
Ist aber hier mehr zur Verwirrung als aus konkretem Grund eingesetzt.
Noe. Nimm einen (kranken) Dateinamen wie z.B. (ein Name!):
/tmp/test/kranke_dateinamen/"foo" und "bar"
Okay, sehe ich ein... Gruß Christoph -- Christoph Maurer - 52072 Aachen - Tux#194235 mailto:christoph-maurer@gmx.de - http://www.christophmaurer.de Auf der Homepage u.a.: Installation von SuSE 7.0 auf Notebook Acer Travelmate 508 T, Elektrotechnik an der RWTH Aachen