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

Re: variable assignment in a script using globsubst



On Wed, May 18, 2005 at 10:49:10AM +0100, Peter Stephenson wrote:
> Vincent Stemen wrote:
> > Any idea why this works from the command line,
> > 
> > $ setopt globsubst
> > $ files=/bin/c*; echo $files
> > /bin/cat /bin/chflags /bin/chio /bin/chmod /bin/cp /bin/csh
> > 
> > but in a script, it does not?
> > 
> > The script works if I set globassign in the script, but it assigns it
> > as an array rather than a string.  However, the manual says, this
> > about globassign.
> >     "This option is provided for backwards compatibility only"
> > 
> > Am I overlooking some other option that could be affecting it?
> 
> No, it must simply be that you have globassign set interactively, e.g.
> in .zshrc or /etc/zshrc.  It always assigns an array; you'll find
> in the interactive case $files[1] is /bin/cat.  It's "for backwards
> compatibility only" exactly because of this confusion: the syntax says
> "scalar", but the glob says "array".
> 
> files=(/bin/c*)
> 
> is the right way to do this.

Thanks for the reply Peter.

No, I "unsetopt globassign" to make sure, even though it did not show
in the list of currently set options, but it still works from the
command line.  I was trying to do it this way because the script I am
working on is running in sh emulation mode and doing it as
"files=/bin/c*" assigns it as a single string.  I ended up going ahead
and changing the one function to zsh mode and doing it as a list to
get around the problem, but I wonder if I have stumbled onto a bug
here.

-- 
Vincent Stemen
Avoid the VeriSign/Network Solutions domain registration trap!
Read how Network Solutions (NSI) was involved in stealing our domain name.
http://inetaddresses.net/about_NSI.html



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