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

Re: Bug with unset variables



On Wed, Nov 11, 2020 at 11:02 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Wed, Nov 11, 2020 at 5:56 PM Felipe Contreras
> <felipe.contreras@xxxxxxxxx> wrote:
> >
> > If I actually do something on the foo() function:
> >
> >   typeset var
> >   [[ -n "$1" ]] && var=$1
> >   echo "var: '${var-other}'"
> >
> > I would expect two things: 1) var is not set when I exit the function,
> > and 2) var is not set until I specifically set it.
> >
> > I can get both in ksh and bash, but not in zsh. In zsh I have to
> > choose either 1) with typeset, or 2) by removing typeset.
> >
> > How do you suggest I get both in zsh?
>
> Add `unset var` right after `typeset var`.

And what is the reason why this is not the default?

Not only does this behavior differ from all other shells, but
basically all languages.

Either way, if "emulate ksh" is supposed to emulate ksh, then it's not
working properly in this instance.

-- 
Felipe Contreras




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