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

Re: Bug with unset variables



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

Roman.




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