Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.shell > #26923

Re: Variable var names

From Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups comp.unix.shell
Subject Re: Variable var names
Date 2026-06-13 13:15 +0200
Organization A noiseless patient Spider
Message-ID <110je4o$2097v$4@dont-email.me> (permalink)
References <n91qs8Fk65fU1@mid.individual.net> <110ghv7$2175u$1@news.xmission.com> <n94pobF3vrqU1@mid.individual.net>

Show all headers | View raw


On 2026-06-13 12:29, Frank Winkler wrote:
> On 12.06.2026 11:02, Kenny McCormack wrote:
> 
>   >I don't know much about ksh, but in bash, you can (and, IMHO, you 
> should)
>   >use the "nameref" functionality.
> 
> I'm still trying to figure out how exactly that works ... ut thanks for 
> the hint!

With ksh93 Kornshell introduced "namerefs" as 'typeset -n' or as
alias 'nameref' as alternate form. They were mainly introduced to
support the concept of _reference parameters_ for functions.

   function change_it
   {
     nameref one=$1   # arg1 is a variable (reference) name
     one="new value"
   }

   var="old value"
   change_it var   # pass a variable name as reference
   echo $var

Above the 'var' passed to the function can be changed within the
function if the respective argument is declared as reference.
Within the function you use the reference name but actually the
function operates on the variable whose name has been provided
with the function call. That way you can use the same function
to change various variables (and does not require to use an own
[unsafe] 'eval'-based mechanism to emulate such a functionality.)

Janis

Back to comp.unix.shell | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Variable var names Frank Winkler <usenet@f.winkler-ka.de> - 2026-06-12 09:30 +0200
  Re: Variable var names gazelle@shell.xmission.com (Kenny McCormack) - 2026-06-12 09:02 +0000
    Re: Variable var names Frank Winkler <usenet@f.winkler-ka.de> - 2026-06-13 12:29 +0200
      Re: Variable var names gazelle@shell.xmission.com (Kenny McCormack) - 2026-06-13 11:14 +0000
      Re: Variable var names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-13 13:15 +0200
  Re: Variable var names ram@zedat.fu-berlin.de (Stefan Ram) - 2026-06-12 11:26 +0000
    Re: Variable var names ram@zedat.fu-berlin.de (Stefan Ram) - 2026-06-12 11:38 +0000
      Re: Variable var names Frank Winkler <usenet@f.winkler-ka.de> - 2026-06-12 14:07 +0200
        Re: Variable var names ram@zedat.fu-berlin.de (Stefan Ram) - 2026-06-12 12:31 +0000
          Re: Variable var names Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-13 02:48 +0000
  Re: Variable var names Christian Weisgerber <naddy@mips.inka.de> - 2026-06-12 12:12 +0000
    Re: Variable var names Frank Winkler <usenet@f.winkler-ka.de> - 2026-06-12 15:19 +0200
    Re: Variable var names Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-13 02:51 +0000
  Re: Variable var names Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2026-06-12 13:42 +0100
  Re: Variable var names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-12 17:41 +0200
    Re: Variable var names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-12 17:54 +0200
    Re: Variable var names Frank Winkler <usenet@f.winkler-ka.de> - 2026-06-13 12:32 +0200
      Re: Variable var names Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-14 01:12 +0000
  Re: Variable var names Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-13 00:20 +0000
  Re: Variable var names Kaz Kylheku <046-301-5902@kylheku.com> - 2026-06-23 21:25 +0000
    Re: Variable var names Helmut Waitzmann <nn.throttle@erine.email> - 2026-06-24 10:45 +0200
    Re: Variable var names Christian Weisgerber <naddy@mips.inka.de> - 2026-06-24 11:41 +0000

csiph-web