URL: https://linuxfr.org/forums/programmation-shell/posts/passage-de-variable-depuis-une-boucle Title: Passage de variable depuis une boucle Authors: bugjargal Date: 2005年01月07日T17:39:11+01:00 Tags: Score: 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 () { £spaces£ £/spaces£if [ -e exctract.log ] £spaces£ £/spaces£then £spaces£ £/spaces£cat < exctract.log | while true £spaces£ £/spaces£do £spaces£ £/spaces£read temp_line2 £spaces£ £/spaces£if [ "$temp_line2" = "" ]; then break; fi £spaces£ £/spaces£tablespace2=$temp_line2 £spaces£ £/spaces£echo tablespace= "$tablespace" £spaces£ £/spaces£echo tablespace2= "$tablespace2" £spaces£ £/spaces£if [ "$tablespace" = "$tablespace2" ] £spaces£ £/spaces£then £spaces£ £/spaces£already_exists="1" £spaces£ £/spaces£break £spaces£ £/spaces£else £spaces£ £/spaces£already_exists="0" £spaces£ £/spaces£fi £spaces£ £/spaces£done £spaces£ £/spaces£echo already_exists= $already_exists £spaces£ £/spaces£return $already_exists £spaces£ £/spaces£fi } cat < hwi1_tlbspc.log | while true do £spaces£ £/spaces£read temp_line £spaces£ £/spaces£let "line_cnt++" £spaces£ £/spaces£set -- $temp_line £spaces£ £/spaces£table=1ドル £spaces£ £/spaces£tablespace=2ドル £spaces£ £/spaces£if [ "$line_cnt" -eq 1 ]; then echo $tablespace > exctract.log; fi £spaces£ £/spaces£already=`compare_files` £spaces£ £/spaces£echo already= $already £spaces£ £/spaces£if [ $already -eq 0 ] £spaces£ £/spaces£then £spaces£ £/spaces£echo $tablespace >> exctract.log £spaces£ £/spaces£fi £spaces£ £/spaces£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...

AltStyle によって変換されたページ (->オリジナル) /