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

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



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).

Peace.

-- 
Karsten M. Self <kmself@ix.netcom.com>        http://kmself.home.netcom.com/
 What Part of "Gestalt" don't you understand?
   We freed Dmitry!        Boycott Adobe!         Repeal the DMCA!
     http://www.freesklyarov.org



Reply to: