Thanks to all whose replies are on their way, and to Claude Charest.
IT WORKS !
Summary:
This is "supposed normal" because:
----------- man sh -----------
...cut here...
Because commands in pipelines are run as separate processes,
variables set in a pipeline have no effect on the parent
shell.
.....
------------ end man page ----------
Use ksh and it will work !!!
Original:
My counter is getting re-set back to zero after it leaves a while
loop. Does anyone know why? Here is a section of code:
#!/bin/sh
SECDIR=`pwd`
num_printers=0
prt_choice()
{
lpstat -p | cut -d" " -f2 | while read tmp
do
num_printers=`expr $num_printers + 1` <<<THIS WORKS
echo $num_printers')' $tmp>>$SECDIR/printers.out
done
echo Num printers = $num_printers <<<<<<< THIS IS ZERO
last=`expr $num_printers + 1`
echo $last')' QUIT>>$SECDIR/printers.out
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:13:18 CDT