bug-bash
[Top][All Lists]
Advanced

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

Re: bash-5.0: problem with variable scoping in posix-mode


From: Martijn Dekker
Subject: Re: bash-5.0: problem with variable scoping in posix-mode
Date: Mon, 28 Jan 2019 23:24:50 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

Op 27-01-19 om 22:59 schreef Chet Ramey:
> This is a consequence of a combination of two POSIX features. First, POSIX
> requires assignment statements preceding special builtins to create global
> variables (POSIX has no local variables) that persist in the shell context
> after the special builtin completes.

Exactly because POSIX has no notion of local variables (but bash does),
I don't think there is anything that requires you to ignore/override
bash local variables in this context. Any fully POSIX-compliant script
will not use local variables, so is not affected either way. I think
that leaves you free to do the logical thing and keep the scope local as
defined by the user.

>  Second, POSIX requires* that
> assignment statements preceding function calls have the same variable-
> assignment behavior as special builtins.

When combining POSIX mode with a bash local variable scope, I would take
that to mean the assignment should persist for as long as the local
scope does.

[...]
> (*) The most recent version of the standard has removed this requirement
> for shell functions, and I will change that behavior for the next release
> of bash.

Thank you for that. dash and yash recently got rid of that behaviour, I
hope other shell authors will also follow suit...

- M.



reply via email to

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