local variables in bash

Merrill Oveson moveson at gmail.com
Thu Feb 12 17:24:09 MST 2009

Look at the following bash code:

func ()
  echo "\"loc_var\" in func = $loc_var"

func2 ()
  echo "loc_var inside another function is" $loc_var
  local loc_var=23


echo "\"loc_var\" outside function = $loc_var"
exit 0

If you run this, you'll notice that loc_var prints as 23.  It should print
as 43.
This is a problem with bash - that is if one function calls another the
value of the local variables are seen.

Does the C shell handle this correctly?

More information about the PLUG mailing list