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

Re: variable assignment in a script using globsubst



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.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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