[linux-l] bash read interactive

Ivan F. Villanueva B. iv at artificialidea.com
Mi Okt 31 14:39:24 CET 2007


Hallo Volker,
erstmal vielen Dank.

Am Mi, Okt 31, 2007 11:24:09 +0100, Volker Grabsch schrieb:
> On Wed, Oct 31, 2007 at 10:58:47AM +0100, Ivan F. Villanueva B. wrote:
> > Hallo,
> > warum funktioniert folgendes auf der Konsole nicht?
> > 
> >     [ivan at samsung]% bash -c "for i in * ; do read -e NAME ; mv $i $NAME ; done" 
> >     a
> >     mv: missing destination file operand after `a.txt'
> >     Try `mv --help' for more information.
> 
> Wozu soll das gut sein? Wieso schreibst du nicht direkt:
> 
>     for i in * ; do read -e NAME ; mv $i $NAME ; done
> Welchen Sinn hat es, das ganze nochmal durch "bash -c" zu jagen?

Ich benutze zsh aber weiß nicht, ob "read -e" auch funktioniert.
 
> Außerdem hast du falsch gequotet. Wenn du mit "..." quotest, dann
> werden die Variablen schon *vorher* ersetzt.
> [...]
> Außerdem rate ich dir dringend, $i und $NAME ordentlich zu quoten,
> sowohl dein Shell-Script als auch der "bash -c"-Befehl werden
> große Probleme bei Dateinamen mit Leerzeichen haben. Besser wäre
> daher:
> 
>     bash -c 'for i in * ; do read -e NAME ; mv "$i" "$NAME" ; done'

Oh ja, danke, sehr gut erklärt!


Gut zu wissen.
 
> Alles, was man "schnell hintippt" ist zunächst buggy. Egal, ob
> ein C-Programm oder ein Shell-Script. ;-)

Es hängt natürlich auch von der Sprache ab. Wenn ich in C oder auf Deutsch
etwas schreibe, werden mehr Fehler vorhanden sein (nach dem Kompilieren bzw.
aspell-Einsatz) als z.B. auf Englisch oder in Java.

vg,
-- 
Iván F. Villanueva B.
Open General Artificial Intelligence  --  http://ogai.org
FFII.org Deutschland                  --  http://www.ffii.de
FFII.org España                       --  http://es.ffii.org



Mehr Informationen über die Mailingliste linux-l