RE: Script help needed...

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

 



I'm not sure how bash does it, but in perl the answer would be that your
variable is lexically scoped inside the loop.

Try declaring R at the beginning of the script.

-G

Regards,

Gavin McDonald
========================
EVI Logistic Enterprises
email: me@xxxxxxxxxxxx
phone: (604) 313-3845


> -----Original Message-----
> From: redhat-list-bounces@xxxxxxxxxx [mailto:redhat-list-
> bounces@xxxxxxxxxx] On Behalf Of Magnus Andersen
> Sent: Wednesday, January 04, 2006 12:05 PM
> To: General Red Hat Linux discussion list
> Subject: Script help needed...
> 
> Hi All,
> 
> I'm writing a script that I am going to use to test write data to an nfs
> mount.  I'm having problem with a variable.  The variable R is set inside
> a
> while loop and it is null outside the loop even after it is set.
> 
> Here is a code snippet.  I've attached the whole script if anyone would
> like
> to look at the whole thing.
> 
> if [ ! -f $PIDFILE ]; then
>     touch $PIDFILE
> else
>     # Read PIDFILE and determine if script is already running.
>     cat $PIDFILE | while read LINE
>     do
>         if [ -z "$LINE" ]; then
>             break
>         else
>             #Get PID from PIDFILE
>             OLDPID=`echo $LINE | awk '{ print $1 }'`
>             RUNNING=`ps aux | grep $OLDPID | grep -v grep | wc -l | tr -d
> '
> '`
>             if [ $RUNNING = 0 ]; then
>                 R=0
>             else
>                 (( R = $R + 1 ))
>                 echo $R
>                 LOC=`echo $LINE | awk '{ print $2 }'`
>             fi
>         fi
>     done
> fi
> echo "R = $R"
> 
> The last echo is null even after R is set inside the loop and I don't
> understand why.
> 
> Thanks,
> 
> --
> Magnus Andersen
> Systems Administrator / Oracle DBA
> Walker & Associates, Inc.

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux