bug-bash
[Top][All Lists]
Advanced

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

Re: declare a="$b" if $a previously set as array


From: Dan Douglas
Subject: Re: declare a="$b" if $a previously set as array
Date: Mon, 15 Dec 2014 14:28:51 -0600
User-agent: KMail/4.14.3 (Linux/3.17.3; KDE/4.14.3; x86_64; ; )

On Wednesday, December 10, 2014 10:43:45 AM Stephane Chazelas wrote:
> David Korn mentions that local scoping a la ksh was originally rejected by
> POSIX because ksh88 originally implemented "dynamic scoping" (like most
> shells now do, but most other languages don't). ksh changed to lexical
> scoping in ksh93 (probably partly to address that POSIX /requirement/) and
> now everyone else wants dynamic scoping because that's how most shells have
> implemented it in the interval.

A local builtin and dynamic scope is in the current beta of ksh.

I don't care very much for how it works though. It's only enabled as a part of
"bash mode", which actively disables a bunch of ksh features and doesn't allow
you to pick and choose. Bash mode is "all or nothing" at least as of the last
snapshot, with no tunables like zsh's setopt.

         $ ksh -c 'function f { typeset x="in f"; g; typeset -p x; }; function 
g { x="in g"; }; x=global; f; typeset -p x'
        x='in f'
        x='in g'

         $ ( exec -a bash ksh -c 'function f { typeset x="in f"; g; typeset -p 
x; }; function g { x="in g"; }; x=global; f; typeset -p x' )
        x='in g'
        x=global

I would have much preferred if David Korn followed his original proposal of
adding dynamic scope for only POSIX-style function definitions across the
board. At least porting bash scripts will be slightly easier in the very
specific case that ksh is invoked correctly.

-- 
Dan Douglas



reply via email to

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