help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Updating global variable from recursing function.


From: Frans de Boer
Subject: Re: [Help-bash] Updating global variable from recursing function.
Date: Mon, 02 Apr 2012 21:08:12 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.28) Gecko/20120306 SUSE/3.1.20 Thunderbird/3.1.20

On 04/02/2012 02:32 PM, Greg Wooledge wrote:
On Sun, Apr 01, 2012 at 01:18:53AM +0200, Frans de Boer wrote:
   iMDirNest=$((iMDirNest+1))
   if [[ iMDirNest >  iHiMDirNest ]]; then
     let iHiMDirNest=$iMDirNest
   fi

That part's wrong for sure.  You are performing a string comparison in
the [[ command, not an integer comparison.  It should be:

   if (( iMDirNest >  iHiMDirNest )); then

I didn't look at the rest.
Strange, it is working fine, the counter is incremented but the result is never propagated to the real global variable, as shown by the bash -x output.

Every time the function returns to the caller, the iHiMDirNest is restored to the level it was before being calling.

Anyone having another suggestion?

Frans.



reply via email to

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