0
ls -l ${1}/${2}/${i}*| awk '{  print  $5 " " $6 " " $7 " " $8 " " $9}' | ( while read Taille Mois Jour HeureOuAnnee Fichier

         do
            DateFichierEntreHierAujourdhui $Mois $Jour $HeureOuAnnee
            if [ $? -eq 0 ]
            then
                  NbFicREcu_links=`expr ${NbFicREcu_links} + 1`
            fi                
         done

         if [ $NbFicREcu_links -eq 0 ]
         then
            echo 'i am here 1'
            echo ${i}
            INT14_KO_FR=1
         else   
            echo 'i am here 2'
         fi
         )       
         fi
echo "1- in the end of the fonction INT14_KO_FR=${INT14_KO_FR}"

This piece of code detects if it lacks of specific files. In fact, when we go into the block which prints 'i am here 1', i want to do INT14_KO_FR=1. But when I quit this loop, INT14_KO_FR is always 0, the initial value. The code enter into 'i am here 1' for 2 times. It's really weird, thank u guys for your help

1 Answer 1

0

The pipe is run in a subshell, so any variables set inside it are not in scope for the outside code. Different workarounds are mentioned there, depending on which language features you are familiar with and whether you need to be POSIX compatible.

2
  • That's really helpful! But I'd better not destroy the previous work done by the others. Is it possible to do this affection? with a pipe in a subshell?
    – ZHE.ZHAO
    May 19, 2014 at 14:37
  • If you want to keep the value you have to either store it in a file or use a different structure, as explained in the last link.
    – l0b0
    May 19, 2014 at 14:41

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.