Programmation.shell : Passage de variable depuis une boucle

Posté par bugjargal () le 07 janvier 2005
0

Bonsoir à tous,

Voici un petit script problématique, il est censé trier le contenu d'un fichier texte.

end_seq="PK_WO_YES_NO WORKORDER_IDX"
line_cnt=0

compare_files ()
{
if [ -e exctract.log ]
then
cat < exctract.log | while true
do
read temp_line2
if [ "$temp_line2" = "" ]; then break; fi

tablespace2=$temp_line2
echo tablespace= "$tablespace"
echo tablespace2= "$tablespace2"
if [ "$tablespace" = "$tablespace2" ]
then
already_exists="1"
break
else
already_exists="0"
fi
done
echo already_exists= $already_exists
return $already_exists
fi
}

cat < hwi1_tlbspc.log | while true
do
read temp_line
let "line_cnt++"


set -- $temp_line
table=$1
tablespace=$2
if [ "$line_cnt" -eq 1 ]; then echo $tablespace > exctract.log; fi

already=`compare_files`

echo already= $already

if [ $already -eq 0 ]
then
echo $tablespace >> exctract.log
fi

if [ "$temp_line" = "$end_seq" ]; then break; fi
done


A l'execution j'obtiens une jolie série de :
already= tablespace= WORKORDER_IDX tablespace2= ALERT already_exists=
UStablespaces.sh: line 52: [: too many arguments

En résumé, la variable already_exists dans la fonction n'est pas transmise à la sortie de la boucle dans laquelle elle est initialisée.
Quelqu'un peut me dire ce que je manque ?

Merci d'avance...

> Lire le message (5 commentaires, moyenne: 1,2).  

Vous avez demandé le commentaire #519751.

Precision

Posté par bugjargal () le 10/01/2005 à 10:29. (lien). Évalué à 1.

cat < $FILE_EXT | while true
		do
			read temp_line2
			if [ "$temp_line2" = "" ]; then break; fi
			tablespace2=$temp_line2
			echo tablespace fr= "$tablespace"
			echo tablespace2= "$tablespace2"
			if [ "$tablespace" = "$tablespace2" ]
			then
				already_exists="1"
				echo already_exists 28= $already_exists 
				break
			else
				already_exists="0"
				echo already_exists 32= $already_exists
			fi
			echo already_exists 34= $already_exists
		done
		echo already_exists 36= $already_exists
	fi
	echo already_exists 39= $already_exists
Renvoie : tablespace fr= ALERT_IDX tablespace2= ALERT already_exists 32= 0 already_exists 34= 0 already_exists 36= already_exists 39= already_exists 61= 0 tablespace fr= ALERT_IDX tablespace2= ALERT already_exists 32= 0 already_exists 34= 0 tablespace fr= ALERT_IDX tablespace2= ALERT_IDX already_exists 28= 1 already_exists 36= 0 already_exists 39= 0 already_exists 61= 0 tablespace fr= ALERT_IDX tablespace2= ALERT already_exists 32= 0 already_exists 34= 0 tablespace fr= ALERT_IDX tablespace2= ALERT_IDX already_exists 28= 1 already_exists 36= 0 already_exists 39= 0 already_exists 61= 0 Donc c'est bien already_exists qui ne passe pas correctement la sortie de la boucle... Je comprends pas mais alors pas du tout...

[ Répondre ]

  • [^]Re: Precision

    Posté par bugjargal () le 10/01/2005 à 10:40. (lien). Évalué à 1.

    Excusez moi, comme ça ce sera plus lisible :

    tablespace fr= ALERT_IDX
    tablespace2= ALERT
    already_exists 32= 0
    already_exists 34= 0
    already_exists 36=
    already_exists 39=
    already_exists 61= 0

    tablespace fr= ALERT_IDX
    tablespace2= ALERT
    already_exists 32= 0
    already_exists 34= 0
    tablespace fr= ALERT_IDX
    tablespace2= ALERT_IDX
    already_exists 28= 1
    already_exists 36= 0
    already_exists 39= 0
    already_exists 61= 0

    tablespace fr= ALERT_IDX
    tablespace2= ALERT
    already_exists 32= 0
    already_exists 34= 0
    tablespace fr= ALERT_IDX
    tablespace2= ALERT_IDX
    already_exists 28= 1
    already_exists 36= 0
    already_exists 39= 0
    already_exists 61= 0

    [ Répondre ]