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

Re: OT: shell scripts and spaces in file/folder names



On Don, 17 Apr 2003 at 21:58 (+0100), Karsten M. Self wrote:
> on Thu, Apr 17, 2003 at 01:03:28PM -0700, Alvin Oga (aoga@Maggie.Linux-Consulting.com) wrote:
> > 
> > 
> > On Thu, 17 Apr 2003, Joris Huizer wrote:
> > 
> > > for i in `ls .`
> > > do
> > >   #...
> > > done
> > 
> > try ...  (untested )
> > #
> > # note star instead of dot ...important...
> > #
> > #	dont forget to cd /someplace/first
> > #	and make sure cd worked
> > #
> > for i in ` ls * `
> > do
> >   ls -la ' $i '
> > done
> > 
> 
> Nope.  
> 
>   - Environment variables don't resolve in single quotes.  "$i" will
>     work.
> 
>   - You're now referring to the file " foo bar ", not "foo bar".
>     Quoting includes whitespace, including whitespace around the quoted
>     string.  "$i" will give you "foo bar".
> 
> Note that you have to re-quote if you're re-evaluating the command.
> Which is among the reasons spaces are so nasty.  Particularly, say, in
> URLs (quoting errors are a large class of Web errors and security
> holes).

... and try

for i in *

instead of 

for i in `ls *`

You don't need to start a ls command to expand the * - the bash
itself can do it.

Jan



Reply to: