patchThe GNU Bourne-Again SHell - Patches: patch #10498, Proposal/Introduction of -S flag...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #10498: Proposal/Introduction of -S flag for local/declare builtins

Submitter:  Dominik Kummer <domson>
Submitted:  Wed 29 Jan 2025 01:30:56 AM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Wont Do Privacy:  Public
Assigned to:  None Open/Closed:  Open

Jump to the original submission

Sat 01 Feb 2025 02:06:50 PM UTC, comment #6: 

PS: I add the patch containing the diff between dynamic_cell and static_scope for additional clarity.

(file #56842)

Dominik Kummer <domson>
Sat 01 Feb 2025 01:34:38 PM UTC, comment #5: 

As already announced I post the patch here. The patch contains the diff between latest master and my private feature branch. Unfortunately the patch also includes patch #10453 and #10454 (dynamic cell).

It is a minimal patch, concise implementation and tested against the latest bash git version.

Here is a test example:

    parent () { local dynscopevar=ok1; local -S statscopevar=ok2; child; echo parent: dynscopevar=$dynscopevar, statscopevar=$statscopevar; }; child () { echo child: dynscopevar=$dynscopevar, statscopevar=$statscopevar; echo child: set dynscopevar to 'ok3', set statscopevar to 'ok4'; dynscopevar=ok3; statscopevar=ok4; }; parent

Kind regards,

Dominik Kummer

(file #56841)

Dominik Kummer <domson>
Wed 29 Jan 2025 10:20:15 PM UTC, comment #4: 

Yes I know, but I don't expect an integration. Nonetheless I can propose a working patch here. Or in worst case patch a custom build locally. First I'd have to implement and test it's usability beforehand anyhow.

Dominik Kummer <domson>
Wed 29 Jan 2025 09:58:29 PM UTC, comment #3: 

I would not expect a patch to be integrated.

Chet Ramey <chet>
Group administrator
Wed 29 Jan 2025 08:19:29 PM UTC, comment #2: 

Oh, so the -S flag is semantically perfectly suited for Static Scoping!
In some cases the flag could just have a calming effect to me.
I'll post a patch here soon, and hope for additional support.

Dominik Kummer <domson>
Wed 29 Jan 2025 07:10:45 PM UTC, comment #1: 

This is static scoping, and I'm not particularly interested in implementing or supporting it.

Chet Ramey <chet>
Group administrator
Wed 29 Jan 2025 01:30:56 AM UTC, original submission:  

I want to propose and implement a -S flag to indicate that the variable will only be visible and modifiable in the current scope, but not in child scopes.

As declare and local are basically provided inside functions to avoid variable polution of the global scope, and protection from parent modification, the -S flag shall be provided complementary to avoid variable polution of the child scopes, and to protect from child modification of the current scope.

Actually I would prefer to have local builtin already implicate -S flag, but I am afraid that will break already existing scripts.
Using `local v1;` as a rule of thumb already protects the current function scope from parent and global scopes.
But still the argument for the -S flag holds, because it can protect the local variable from unintended child modification and therefore from unexpected behavior.

The -S flag could help secure execution of nested-function-driven scripts, where subshells are too expensive.

What do you think? Please leave a comment with contra (or even pro) arguments.

The relevant patches will be delivered as attachments here, if bash inner structure even allows this feature

Dominik Kummer <domson>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by domson (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-02-01 domson Attached File- Added introduce_static_scope.patch, #56842
    2025-02-01 domson Attached File- Added introduce_dynamic_value_and_static_scope.patch, #56841
    2025-01-31 chet StatusNone Wont Do

    Back to the top

    Powered by Savane 3.14-7003.
    Corresponding source code