Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 10-13-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,434

Code:
#!/bin/ksh

echo > aux

while read label
do
   valor=1
   echo $label | grep "AS-"
   if [ $? -eq 0 ]
   then
      while read labelold
      do
         if [ "${label}" = "${labelold}" ]
         then
            #echo "encon" >aux2
            valor=0
            echo $valor
            break
         fi
         echo $valor #<--- Allways is 1
      done < hosts.old
      if [$valor -eq 1]
      then
         echo "$label" >> aux
      fi
   fi
done < hosts

After assigning the value 0 to your variable, you break the while loop so you never display the variable with the new value 0.

Whith KSH the modification of variable inside loops aren't lost (that is not the case with bourne shell).
Try the following script:
[CODE]var=init
ls | while read file
do
var="Last file is $file"
done



Jean-Pierre.

Last edited by aigles; 10-13-2006 at 08:46 AM..