zsh-users
 help / color / mirror / code / Atom feed
* set -o nounset; foo=(); print ${foo:#bar}
@ 2014-09-06 18:47 Roman Neuhauser
  2014-09-06 19:34 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Roman Neuhauser @ 2014-09-06 18:47 UTC (permalink / raw)
  To: zsh-users

hello,

i encountered a behavior i don't like and would like to get rid of. :)

  roman@wrench ~ 0 1074 0 > print $ZSH_VERSION
  5.0.5
  roman@wrench ~ 0 1075 0 > set -o nounset
  roman@wrench ~ 0 1076 0 > foo=()
  roman@wrench ~ 0 1077 0 > print $foo

  roman@wrench ~ 0 1078 0 > print ${foo:#bar}
  zsh: foo: parameter not set
  roman@wrench ~ 0 1079 1 > 

the problematic part is ${foo:#bar} triggering nounset.  FMPOV it *is*
set (but null), so i'd say the observed behavior is a bug.

is it fixable?  or is there at least a good workaround?  (stuffing the
array with a sentry is not a good workaround.)

-- 
roman


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

* Re: set -o nounset; foo=(); print ${foo:#bar}
  2014-09-06 18:47 set -o nounset; foo=(); print ${foo:#bar} Roman Neuhauser
@ 2014-09-06 19:34 ` Bart Schaefer
  2014-09-06 20:13   ` Roman Neuhauser
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-09-06 19:34 UTC (permalink / raw)
  To: Roman Neuhauser, zsh-users

On Sep 6,  8:47pm, Roman Neuhauser wrote:
}
}   roman@wrench ~ 0 1078 0 > print ${foo:#bar}
}   zsh: foo: parameter not set
}   roman@wrench ~ 0 1079 1 > 
} 
} the problematic part is ${foo:#bar} triggering nounset.  FMPOV it *is*
} set (but null), so i'd say the observed behavior is a bug.

This seems to be ${name:#word} being confused with ${name:?word} where
the ":" means to treat an empty parameter as unset.  This also affects
the newer ${name:^word} form.

} is it fixable?

I don't immediately see a simple code change that would do so, but I'm
sure it can eventually be fixed.

} or is there at least a good workaround?  (stuffing the
} array with a sentry is not a good workaround.)

You can use ${foo##bar(#e)} with extendedglob, I think, but it may
depend on context.  Without extendedglob I don't see a good way.


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

* Re: set -o nounset; foo=(); print ${foo:#bar}
  2014-09-06 19:34 ` Bart Schaefer
@ 2014-09-06 20:13   ` Roman Neuhauser
  0 siblings, 0 replies; 3+ messages in thread
From: Roman Neuhauser @ 2014-09-06 20:13 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

# schaefer@brasslantern.com / 2014-09-06 12:34:33 -0700:
> I don't immediately see a simple code change that would do so, but I'm
> sure it can eventually be fixed.

cool!  btw will this be tracked somewhere?

> You can use ${foo##bar(#e)} with extendedglob, I think, but it may
> depend on context.  Without extendedglob I don't see a good way.

(reminder to self: (#e) is like $ in REs)

thanks a lot!  extendedglob is fine and the workaround works perfectly.

-- 
roman


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

end of thread, other threads:[~2014-09-06 20:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-06 18:47 set -o nounset; foo=(); print ${foo:#bar} Roman Neuhauser
2014-09-06 19:34 ` Bart Schaefer
2014-09-06 20:13   ` Roman Neuhauser

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