Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Two simple questions



    Hi Tero :)

 * Tero Niemela <tero_niemela@xxxxxxxxx> dixit:
> > > 0) I'm seeing dirs like /bin /bin/ and even /bin//
> > in
> > > my PATH.
> > You're looking
> > for something like (EXTENDED_GLOB must be set, for
> > the '#'):
> >     path=(${(qq)${path//\/##/\/}%/})
> > 
> >     This converts multiple slashes to just one, and
> > then removes the
> > last one. The '(qq)' part is needed just in case
> > 'path' has elements with spaces in it.
> In some cases (Cygwin) it indeed does have spaces.
> However, your solution seems not to be optiomal:
> ~> export PATH=/bin:/usr/bin:/bin//:/bin/
> ~> which ls                              
> /bin/ls
> ~> path=(${(qq)${path//\/##/\/}%/})
> ~> echo $PATH
> '/bin':'/usr/bin':'/bin/'
> ~> which ls
> ls not found
> zsh: exit 1
> ~> 

    The slash removing works here. It seems you don't have
'EXTENDED_GLOB' set. You must in order the recipe to work ;)

    And yes, the quoting completely screws the functioning of the
PATH, and the worst thing is that... it is not needed O:) Array
elements are separate words, so you just need to do this:

    setopt EXTENDED_GLOB
    path=(${${path//\/##/\/}%/})
    unsetopt EXTENDED_GLOB

    The setopt is only needed, obviously, if you don't have
EXTENDED_GLOB set, which you don't seem to have.

    Hope this helps :) At least it works for me with your example
above (and adding a directory with spaces in it.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



Messages sorted by: Reverse Date, Date, Thread, Author