bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] local_builtin: do not overwrite previously saved options wit


From: Dale R. Worley
Subject: Re: [PATCH] local_builtin: do not overwrite previously saved options with local -
Date: Mon, 06 Feb 2023 10:18:30 -0500

This is tricky.  The documentation is

     If NAME is '-', the set of shell options is made
     local to the function in which 'local' is invoked: shell options
     changed using the 'set' builtin inside the function are restored to
     their original values when the function returns.

It does seem to mean that executing 'local -' causes the "original"
values to be restored.  I could argue that "original" in this context
could mean either just before the "set" is executed or just as the
funciton is entered, but both have the same result.  The tricky part is
this is *retrospective*, the options may have already been changed in
this function invocation:

And bash 5.1.0 doesn't do that:

    $ function a () { set -C ; local -; }
    $ echo $-
    bhimBHs
    $ a
    $ echo $-
    bhimBCHs
    $

The behavior of bash appears to be is "future changes in shell options
using the 'set' builtin inside the current function invocation are
restored to their prior values when the function returns".

Dale



reply via email to

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