[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [despammed] Kleines Programmierproblem (bash)



Thilo Engelbracht writes:
> Auszug aus einem Shell-Skript:
> 
> for name in verzeichnis/*
> do
>     cat $name
> done
> 
> Die Inhalte aller Dateien, die im Verzeichnis "verzeichnis" vorhanden sind,
> werden auf dem Monitor ausgegeben.
> 
> Wenn aber keine Dateien im Verzeichnis vorhanden sind ("verzeichnis" also
> leer ist), erhalte ich beim Ausführen des Skriptes eine Fehlermeldung.
> Zuerst dachte ich, dass ich mein Problem mit dem "test"-Befehl lösen kann.
> Leider hat mir die Manpage zu "test" nicht weitergeholfen...........

   Pathname Expansion
       After word splitting, unless the -f option has  been  set,
       bash  scans  each word for the characters *, ?, and [.  If
       one of these characters appears, then the word is regarded
       as  a  pattern, and replaced with an alphabetically sorted
       list of file names matching the pattern.  If  no  matching
       file  names  are  found,  and the shell option nullglob is
       disabled, the word is left  unchanged.   If  the  nullglob
       option  is  set,  and  no  matches  are found, the word is
       removed.

wirth@katla:~> for i in asdf* ; do echo $i; done
asdf*
wirth@katla:~> shopt -s nullglob
wirth@katla:~> for i in asdf* ; do echo $i; done
wirth@katla:~>



Reply to: