Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   Variable Scope Problems (http://www.programmingforums.org/showthread.php?t=860)

elmo Oct 14th, 2004 2:32 PM

alright, i got some code like this:

:

function foo() {
  echo "var: $var"
}

function bar() {
  for i in `seq 10 10 100`; do
    var=$(($var + $i))
    echo $i
  done
}

bar
foo


this will set var to some value, and echo $i

if i try to add some nifty stuff to the second function

:

...
function bar() {
  for i in `seq 10 10 100`; do
    var=$(($var + $i))
    echo $i
  done | dialog --gauge "ra ra ra" 10 20 0
}
...


the gauge will work, but var wont be set to anything due to variable protection (or some such).

Is there any way around this, so that var will be accesible in foo()?

Vorlin Feb 28th, 2005 5:11 PM

Change the
:

done | dialog --guage "ra ra ra" 10 20 0
to
:

done && dialog --guage "ra ra ra" 10 20 0
. The | declares you to send the output from the previous command when nothing was passed from the for loop.


All times are GMT -5. The time now is 1:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC