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

wrong "export -p" output for exported but not set variables (Was: PATCH: [[ -v varname ]])



2016-09-15 12:08:54 +0100, Stephane Chazelas:
[...]
> declared (or exported or marked readonly) with different types
> but not assigned to (at least in zsh, declared/exported
> variables are always given a default value)
[...]

Actually, I was wrong about that and was basing it on the output
of typeset -p.

$ zsh -c 'export a; export -p a'
typeset -x a=''

(BTW, it would be nice to have sh-compatible (POSIX at least) output in:
$ ARGV0=sh zsh -c 'export a; export -p a'
typeset -x a=''
)

$ zsh -c 'export a; printenv a'
$ zsh -c 'export a=; printenv a'

$

$a was not given a default empty value there. It's considered as set though:

$ zsh -c 'export a; echo ${a+foo}'
foo

Which I think breaks POSIX compliance (and no other shell
outputs foo there)..

It's different for "readonly":

$ zsh -c 'readonly a; echo ${a+foo}'
foo
$ ARGV0=sh zsh -c 'readonly a; echo ${a+foo}'

$

-- 
Stephane



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