Zitat von
Noether
Ok, also es funktioniert nun hiermit, wenn auch ziemlich lahm:
Ja, das ist bei Bash-Skripten oft so. Aber was soll's, dafür sind sie schnell erstellt
Allerdings gibt's immer noch ein paar Fehler; z. B.:
mv: cannot move `./html/01/07' to a subdirectory of itself, `./html/01/07/07'
mv: overwrite `./html/01/01'? mv: cannot stat `4': No such file or directory
Irgendwelche Vorschläge?
Einfach ignorieren. Wenn's dich so stört, kannst du die Fehlerausgabe nach /dev/null umleiten (`befehl 2> /dev/null).
Mir ist aber noch nicht ganz klar, wieso die Variante mit basename und dirname nicht funktioniert und wieso ${i##*/} und ${i%/*} funktionieren. Kann mich da mal jemand aufklären?
Warum es mit base- und dirname nicht funktioniert, kann ich ad hoc auch nicht erkennen. Warum die Bash-Built-In-Variante funktioniert schon, das erklärt die man page (man bash, dann "Slash eingeben und nach ## suchen):
Code:
${parameter#word}
${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 positional parameter in turn, and the expansion is the
resultant list. If parameter is an array variable subscripted
with @ or *, the pattern removal operation is applied to each
member of the array in turn, and the expansion is the resultant
list.
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname
expansion. If the pattern matches a trailing portion of the
expanded value of parameter, then the result of the expansion is
the expanded value of parameter with the shortest matching pat-
tern (the ``%'' case) or the longest matching pattern (the
``%%'' case) deleted. If parameter is @ or *, the pattern
removal operation is applied to each positional parameter in
turn, and the expansion is the resultant list. If parameter is
an array variable subscripted with @ or *, the pattern removal
operation is applied to each member of the array in turn, and
the expansion is the resultant list.
Lesezeichen