[Top][All Lists]

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

Q: interoperability of local vars and option nounset

From: Nardmann, Heiko
Subject: Q: interoperability of local vars and option nounset
Date: Wed, 23 Feb 2011 14:36:22 +0100

Hi together,

short: is there any way to get informed about unset local variable while
having option 'nounset' activated?

Long: the problem with 'local' is that variable declared this way are
visible inside the children, too. So the behaviour of option 'nounset'
depends on the way a function is called - either with a caller function
with the (locally) unset variable already set or without one.

Lets have a look at my example script:

set -o nounset

function g()
  echo "g: myvar=$myvar"

function f()
  local myvar="test"

  echo "f: myvar=$myvar"



This way all is fine for bash but not for me since myvar is not set
inside g(). So if I call g() directly instead of f() then 'nounset'
gives me the error that I want.

This results into the question whether it is possible to get an error
for such situations, too?

Thanks in advance!

Kind regards

Heiko Nardmann

reply via email to

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