bug-bash
[Top][All Lists]
Advanced

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

Re: nameref and referenced variable scope, setting other attributes (was


From: Zachary Santer
Subject: Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope)
Date: Thu, 14 Mar 2024 11:05:38 -0400

On Thu, Mar 14, 2024 at 10:47 AM Greg Wooledge <greg@wooledge.org> wrote:
>
> I can't seem to duplicate this.  This is with bash 5.2:

Run the whole script from my original email. Maybe I managed to trip
bash up with something I edited out of the last email. Pay particular
attention to var_3.

#!/usr/bin/env bash

func_1 () {
  local var_1='BREAD'
  local var_2='ICE CREAM'
  local var_3='EGG'
  func_2
  printf '%s\n' "func_1:"
  local -p var_1
  local -p var_2
  local -p var_3
}

func_2 () {
  local -n nameref_1=var_1
  local -l nameref_1
  nameref_1='TOAST'
  local -nl nameref_2='VAR_2'
  nameref_2='MILKSHAKE'
  local -n nameref_3='var_3'
  nameref_3='soufflé'
  local var_4='GROUND BEEF'
  local -n nameref_4='var_4'
  local -l nameref_4
  printf '%s\n' "func_2:"
  local -p nameref_1
  local -p var_1
  local -p nameref_2
  local -p var_2
  local -p nameref_3
  local -p var_3
  local -p nameref_4
  local -p var_4
}

func_1



reply via email to

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