zsh-users
 help / color / mirror / code / Atom feed
* variable assignment in a script using globsubst
@ 2005-05-18  4:43 Vincent Stemen
       [not found] ` <zsh@hightek.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Stemen @ 2005-05-18  4:43 UTC (permalink / raw)
  To: zsh-users

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?

# --<script>--
setopt globsubst

files=/etc/c*
echo "$files"
# --</script>--

Output of the script:

/etc/c*

I got the same result on both Linux and BSD.

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?

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: variable assignment in a script using globsubst
       [not found] ` <zsh@hightek.org>
@ 2005-05-18  9:49   ` Peter Stephenson
  2005-05-18 17:22     ` Vincent Stemen
  2005-05-18 17:49   ` Peter Stephenson
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2005-05-18  9:49 UTC (permalink / raw)
  To: zsh-users

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@csr.com>                  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.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: variable assignment in a script using globsubst
  2005-05-18  9:49   ` Peter Stephenson
@ 2005-05-18 17:22     ` Vincent Stemen
  0 siblings, 0 replies; 5+ messages in thread
From: Vincent Stemen @ 2005-05-18 17:22 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: variable assignment in a script using globsubst
       [not found] ` <zsh@hightek.org>
  2005-05-18  9:49   ` Peter Stephenson
@ 2005-05-18 17:49   ` Peter Stephenson
  2005-05-19 18:28     ` Vincent Stemen
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2005-05-18 17:49 UTC (permalink / raw)
  To: zsh-users

Vincent Stemen wrote:
> 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.

Do you have globsubst set?  In that case, files will be set to /bin/c*
but "echo $files" would expand the glob at that point.

-- 
Peter Stephenson <pws@csr.com>                  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.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: variable assignment in a script using globsubst
  2005-05-18 17:49   ` Peter Stephenson
@ 2005-05-19 18:28     ` Vincent Stemen
  0 siblings, 0 replies; 5+ messages in thread
From: Vincent Stemen @ 2005-05-19 18:28 UTC (permalink / raw)
  To: zsh-users

On Wed, May 18, 2005 at 06:49:25PM +0100, Peter Stephenson wrote:
> Vincent Stemen wrote:
> > 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.
> 
> Do you have globsubst set?  In that case, files will be set to /bin/c*
> but "echo $files" would expand the glob at that point.

Yes.  That is what was happening.  I was thinking globsubst would
cause it to expand even on a variable assignment.  You are right, the
expansion was taking place in my echo statement when I did not have
quotes around $files.  Ok.  I guess I need to stick to doing it as a
list in zsh emulation mode.

Thank you for clarifying that.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-05-19 18:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-18  4:43 variable assignment in a script using globsubst Vincent Stemen
     [not found] ` <zsh@hightek.org>
2005-05-18  9:49   ` Peter Stephenson
2005-05-18 17:22     ` Vincent Stemen
2005-05-18 17:49   ` Peter Stephenson
2005-05-19 18:28     ` Vincent Stemen

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).