[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] test om filer eksisterer i en for loop



Hej,

On 20:47 Thu 10 Jul 2008, Sune Vuorela wrote:
> On 2008-07-10, Anders Thøgersen <sslug@sslug> wrote:
> > Hej,
> >
> > Hvorfor fungerer dette ikke:
> >
> > 	foo() { \ls -1 $HOME; }
> > 	
> > 	for i in $(foo); do
> > 	  [[ -e $i ]] && echo $i
> > 	done
> >
> > Jeg forstår det ikke...  Hvis jeg skriver:
> >
> > 	for i in $(foo); do
> > 	  echo $i
> > 	done
> >
> > Så sker der det jeg forventer,.. hmmm, er der nogen der kan hjælpe mig?
> 
> Hvor står du henne når du skriver det?

I mit hjemme dir.

> Og hvad er det for noget med [[ ]]?
> Og den der \ foran ls ?

[[ ]] er ganske almindelig kort syntax. [[ ... ]] || echo "hallo", fx.

\ foran ls betyder at jeg vil eksekvere ls udenom det alias jeg har
defineret for ls, dvs /bin/ls.

> Jeg gjorde lige:
> 
> foo() { ls -1 $HOME }
> for i in $(foo)
> do
> 	[ -e $i ] && echo $i
> done
> 
> og jeg fik listen af emner der var fælles for pwd og $HOME
> 
> Og tilmed virker det hvis /bin/sh ikke nødvendigvis er bash.

Det er godt at høre at det virker for dig!  Jeg var overbevist om at det
jeg skrev ikke er helt vanvittigt.  Måske har jeg en mærkelig shell
setting?  Jeg kan fx. ikke definere foo() ovenover som du gør uden at
sætte semikolon efter $HOME.  Hvis jeg gør det så vises "continuation"
prompten.

Enkel kantet parantes som du bruger virker på samme måde hos mig, men
jeg synes at kunne huske noget om at det er bedre at bruge [[ ]]. 

Jeg er lige på vej ud af døren, så jeg ser på det igen i morgen.

Mvh.
Anders


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2008-08-01, 02:01 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] *