[Top][All Lists]

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

NOT changing global variables

From: Frans de Boer
Subject: NOT changing global variables
Date: Tue, 19 Dec 2006 22:46:55 +0100

My example problem using Bash 3.00.16 (Suse 9.3)
declare -i var1=2

function dowhat () {
local -i i=0
  echo $i

iretval=$(dowhat argument)
echo $var1
dowhat argument
echo $var1
Okay, the function tries to alter the global var1 integer. But, the
result is that var1 is NOT changed. So, the result of the first echo
will be 0
However, the next echo displays the changed var1 as being 1. At the
expense of losing the return value.

Is there a "magic" way to let the bash functions behave as I would
expect? I need some functions who return a value but also alter other
global variables.

Kind regards,
Frans de Boer. 

reply via email to

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