[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] sætte en variabel i en while-løkke



Peter Makholm <sslug@sslug> wrote on 07-Jan-05:

> Jeg har følgende stump kode:
>
>     #!/bin/bash
>
>     bar=foo
>
>     find . -type f | while read p ; do
>       if /bin/true ; then bar=$p ; fi
>     done
>
>     echo $bar

Du kan prøve med

   #!/bin/bash

   bar=foo

   find . -type f | ( while read p ; do
     if /bin/true ; then bar=$p ; fi
   done

   echo $bar )

for at få kørt "echo" i samme proces som "while". Afhængigt af hvor
kompliceret virkeligheden er, kan det dog godt blive noget pinagtigt.


Fordelen ved at bruge "find" i en pipe (og ikke en "command
substitution") er i øvrigt at "while" så kan starte mens "find" stadig
finder filer. Det kan have relevans hvis der skal søges i store træer.

Endvidere undgår man det buffer-problem, der kan opstå, hvis der
findes flere filer end kommandolinjen kan indeholde.


Anders.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 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] *