[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] BASH: expansion af stjerne *



Peter Makholm wrote:

> Kristian Nørgaard <sslug@sslug> writes:
> 
>> Det er som om *.txt ikke altid expanderes, som jeg forventer. Jeg har
>> ikke helt klar over i hvilke tilfælde det fejler, men ind i mellem får
>> jeg en fejl meddelelse, a la:
> 
> Ifølge SUSv3 skal mønstre der ikke ekspanderer til nogle filer lades
> uændret. Hvis du ikke har nogle filer der hedder noget med .txt vil $f
> altså få den ene værdi '*.txt'.
> 
> Du bliver nødt til at lave noget ala:
> 
> for f in *.txt ; do
>     if [ ! -e $f ] ; then
>         continue
>     fi
> 
>     # Gør noget ved $f
> done
>   

Til hurtige oneliners ynder jeg at bruge noget ala.
for file in `ls *.txt 2>/dev/null` ; do echo $file; done

Der har lidt samme resultat. 
Om der er effektivt eller forkert ved jeg ikke, men fordelen er at 'ls' er
nem at udskifte med grep,find,sed,awk og kombinationer af disse forbundet
med '|'

Mvh.
        Mikael.
   


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *