This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: LS and spaces in path names (the xth)


On Tue, 28 Jun 2005, Andreas Eibach wrote:

> Needless to say that scripts containing
> 
> for i in `ls *.dat*`; do .... 

Ouch!!!

> will NOT work, because Cygwin will interpret each sub-string between the \ ' s separately, making parsing files a nuisance.

That script won't work anywhere.  Who ever writes braindamaged shell
code like that? It takes the output of a command and re-tokenizes it,
so that files with spaces will turn into multiple tokens. You want:

  for i in *.dat* ; do some-command "$i" ; done

The quotes around $i are important too. Or, to be properly paranoid,
you have to watch for "$i" expanding into something that looks like a
command option to some-command. If some-command is properly designed,
it takes the -- option to indicate ``no more options'':

  for i in *.dat* ; do some-command -- "$i" ; done

-- 
Meta-CVS: the working replacement for CVS that has been stable since
2002.  It versions the directory structure, symbolic links and execute
permissions. It figures out renaming on import. Plus it babysits the kids
and does light housekeeping! http://freshmeat.net/projects/mcvs


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]