bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] admit 'typeset' is here to stay


From: Martijn Dekker
Subject: Re: [PATCH] admit 'typeset' is here to stay
Date: Sun, 21 Feb 2016 00:28:54 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

Dan Douglas schreef op 20-02-16 om 21:55:
> "typeset" vs. "declare" isn't always a straightforward decision
> depending on one's requirements. Bash's "typeset" has always
> been there for portability despite being a synonym for "declare",
> so I think just calling it a synonym would be counterproductive.
> http://thread.gmane.org/gmane.comp.standards.posix.austin.general/8371/focus=8377

Am I missing something? I thought they did exactly the same thing in
bash. If I'm not wrong about that, then as far as bash is concerned,
they are in fact synonyms and functionally equivalent.

> It's tricky because the big problems surrounding "typeset" lie in the
> details of variable scope and how each option is supported. There are
> some good reasons for choosing "typeset" if you're willing to work around
> all the subtleties but I think that's a bit beyond a concise description
> for the help output.

'typeset' and 'declare' in bash are both dynamically scoped, aren't
they? Where is the difference between them?

'typeset' in AT&T ksh93 is statically scoped, but ksh93 is the only
shell to have statically scoped local variables -- all the other shells
with 'typeset' (pdksh/mksh, bash, zsh, yash) have it as in ksh88,
dynamically scoped -- and it doesn't look like this is ever going to
change, or it would have changed sometime in the 23 years since ksh93
came out.

> For the most common requirement: localizing or applying an attribute to
> a variable within a single function; "local" and the posix-compatible
> declaration builtins are usually what people want. "local" is supported
> by every current implementation that also has "typeset" and "declare",

That would be bash and zsh only, so that's not very meaningful.

Perhaps you meant "every current implementation that also has
'typeset'", which would be ksh93, pdksh/mksh, bash, zsh, and yash.

However, ksh93, pdksh/mksh, and yash don't have "local".

The latter two have dynamically scoped 'typeset', so on those, you can
simply alias 'local' to 'typeset' to get the same functionality with the
familiar keyword.

But on ksh93, getting the equivalent of a dynamically scoped 'local' is
impossible. It has statically scoped local variables only. See Part III,
Q28 at http://kornshell.com/doc/faq.html

- M.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]