tag=0 for file in Directory_PATH/* do stat_file=`grep "#ST#" $file|cut -d"," -f4` echo "#####$stat_file==" #cat tempimp1|grep "^HS.*"|while read line1 while read line1 do hsval=`grep "^HS."` echo "========$hsval----" if [ "$stat_file" == "$hsval" ] then val=`grep "1001,Duplicate FORE" $file` echo "===sarfaraz" if [ "$val" == " " ] then echo "SUCCESS" #tag=127 else echo "yamamama" tag=127 echo "$tag###########" fi else echo "FILE IS NOT MATCHING " fi done < tempimp1 exit done rm -f tempimp1 echo "------$tag#####" if [ "$tag" == "127" ] then echo "FAILED" exit 127 else echo "FINAL SUCCESS"

In this code i am trying to read multiple file from a directory, grep some value from it. there is another file named "tempimp1" which having two value
1)-HS.SCMC.20120130.CR.1 2)-HS.SCMC.20120130.NW.1 this value should match "if "$stat_file" == "$hsval" " in this scetion i need to match this value. once it match i need to assign tag value. i want to use this assign value outside the while loop.

I Really appriciate for your kind support


In reply to Shell Script Question:- can not read variable that was stored from within a while loop when out of the while loop by sarf13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.