<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: capture exit code of function inside for loop in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496804#M704865</link>
    <description>Hi&lt;BR /&gt;&lt;BR /&gt;do the find twice is the best way&lt;BR /&gt;&lt;BR /&gt;example&lt;BR /&gt;&lt;BR /&gt;param=$1&lt;BR /&gt;find $param &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;if  [ "$?" = "0"  ]&lt;BR /&gt;then&lt;BR /&gt;for a in  $(find $param -name *.log)&lt;BR /&gt;do&lt;BR /&gt;echo  $a&lt;BR /&gt;done&lt;BR /&gt;else&lt;BR /&gt;echo bad&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                Steve Steel</description>
    <pubDate>Thu, 03 Mar 2005 07:17:19 GMT</pubDate>
    <dc:creator>Steve Steel</dc:creator>
    <dc:date>2005-03-03T07:17:19Z</dc:date>
    <item>
      <title>capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496796#M704857</link>
      <description>hi,&lt;BR /&gt;I have this problem running a for loop:&lt;BR /&gt;-----------------------------------------------&lt;BR /&gt;for MONTHTOCHECK in `find /pippo -path "/pippo/*" -prune -name "DC*.DAT*" -type f -mtime +45 |sed s/.*DC/DC/| sort -d | awk '{ printf( substr($1,3,6)"\n" ); }' | uniq`&lt;BR /&gt;do &lt;BR /&gt;echo ciao&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;find: cannot stat /pippo&lt;BR /&gt;$ echo $?&lt;BR /&gt;0&lt;BR /&gt;-----------------------------------------------&lt;BR /&gt;how cah I cpture the exit code of find or any other function inside the for loop?&lt;BR /&gt;&lt;BR /&gt;Thankyou&lt;BR /&gt;Paolo</description>
      <pubDate>Thu, 03 Mar 2005 05:59:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496796#M704857</guid>
      <dc:creator>Paolo Gilli</dc:creator>
      <dc:date>2005-03-03T05:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496797#M704858</link>
      <description>for MONTHTOCHECK in `find /pippo -path "/pippo/*" -prune -name "DC*.DAT*" -type f -mtime +45 |sed s/.*DC/DC/| sort -d | awk '{ printf( substr($1,3,6)"\n" ); }' | uniq`&lt;BR /&gt;export exit_code=$?&lt;BR /&gt;do &lt;BR /&gt;echo ciao&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;echo ${exit_code)&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Thu, 03 Mar 2005 06:11:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496797#M704858</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-03-03T06:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496798#M704859</link>
      <description>HI Paolo,&lt;BR /&gt;&lt;BR /&gt;echo $?&lt;BR /&gt;&lt;BR /&gt;the above will give the status value of last command executed.&lt;BR /&gt;&lt;BR /&gt;See an example.&lt;BR /&gt;&lt;BR /&gt;SVR#-/crash&amp;gt;ls&lt;BR /&gt;bounds                  crash.0                 iostat                  lost+found              web.log.0827_1400hrs.Z&lt;BR /&gt;SVR#-/crash&amp;gt;echo $?&lt;BR /&gt;0&lt;BR /&gt;SVR#-/crash&amp;gt;xyz&lt;BR /&gt;ksh: xyz:  not found&lt;BR /&gt;SVR#-/crash&amp;gt;echo $?&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;This means, for a command which is executed succesfully, the value of $? will be zero. If the last command is not successfull it will give a value which is non zero. This function is the common method which is used to check the exit code, and widely used in shell scripts.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Syam&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Mar 2005 06:17:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496798#M704859</guid>
      <dc:creator>Ranjith_5</dc:creator>
      <dc:date>2005-03-03T06:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496799#M704860</link>
      <description>Something strange with your find command :&lt;BR /&gt;If you use -path instead of -name, path will be used, but leading / removed (see manpage for details). So, you're looking for all files under pippo dir in /pippo (i.e. /pippo/pippo/*). Then you apply -name... very strange.&lt;BR /&gt;&lt;BR /&gt;If I really understand, you want all files under /pippo named DC*.DAT* that have been modified under 45 days, without going into subdirs ? here it is :&lt;BR /&gt;find /pippo/* -prune -type f -name "DC*.DAT*" -mtime +45&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Fred&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Mar 2005 06:28:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496799#M704860</guid>
      <dc:creator>Fred Ruffet</dc:creator>
      <dc:date>2005-03-03T06:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496800#M704861</link>
      <description>One was as,&lt;BR /&gt;&lt;BR /&gt;for file in `find . -type f;echo $?`; do&lt;BR /&gt;echo $file&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Last file data contains $? (return value of find command)&lt;BR /&gt;&lt;BR /&gt;Else try as,&lt;BR /&gt;&lt;BR /&gt;find /pippo -path "/pippo/*" -prune -name "DC*.DAT*" -type f -mtime +45 |sed s/.*DC/DC/| sort -d | awk '{ printf( substr($1,3,6)"\n" ); }' | uniq &amp;gt; /tmp/testlog&lt;BR /&gt;&lt;BR /&gt;if [[ $? -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;  while read line; do&lt;BR /&gt;    echo $line&lt;BR /&gt;  done &amp;lt; /tmp/testlog&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Mar 2005 06:32:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496800#M704861</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-03-03T06:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496801#M704862</link>
      <description>Thank to all,&lt;BR /&gt;What I need is know if it's possible capture the error that can occour in any function inside the for loop.&lt;BR /&gt;So if find,sort,awk or uniq fail, I can capture the exit code !0 and stop the proceure&lt;BR /&gt;&lt;BR /&gt;Anil, your suggestion don't work</description>
      <pubDate>Thu, 03 Mar 2005 06:45:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496801#M704862</guid>
      <dc:creator>Paolo Gilli</dc:creator>
      <dc:date>2005-03-03T06:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496802#M704863</link>
      <description>Paolo,&lt;BR /&gt;I suggest you break your oneliner into seperate steps and check the error code at each step. (find/sed/sort/awk)&lt;BR /&gt;The end result would then be a temporary file with all your data, which you can then process within your loop.&lt;BR /&gt;Regards&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Mar 2005 06:59:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496802#M704863</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-03-03T06:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496803#M704864</link>
      <description>There is a typo in my post.&lt;BR /&gt;echo ${exit_code) needs to as follows.&lt;BR /&gt;echo ${exit_code}</description>
      <pubDate>Thu, 03 Mar 2005 07:00:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496803#M704864</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-03-03T07:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496804#M704865</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;do the find twice is the best way&lt;BR /&gt;&lt;BR /&gt;example&lt;BR /&gt;&lt;BR /&gt;param=$1&lt;BR /&gt;find $param &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;if  [ "$?" = "0"  ]&lt;BR /&gt;then&lt;BR /&gt;for a in  $(find $param -name *.log)&lt;BR /&gt;do&lt;BR /&gt;echo  $a&lt;BR /&gt;done&lt;BR /&gt;else&lt;BR /&gt;echo bad&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                Steve Steel</description>
      <pubDate>Thu, 03 Mar 2005 07:17:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496804#M704865</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2005-03-03T07:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496805#M704866</link>
      <description>you wrote:&lt;BR /&gt;for MONTHTOCHECK in `find /pippo -path "/pippo/*" -prune -name "DC*.DAT*" -type f -mtime +45 |sed s/.*DC/DC/| sort -d | awk '{ printf( substr($1,3,6)"\n" ); }' | uniq`&lt;BR /&gt;export exit_code=$?&lt;BR /&gt;do &lt;BR /&gt;echo ciao&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;echo ${exit_code)&lt;BR /&gt;&lt;BR /&gt;but "export exit_code=$?" is before "do" so the loop don't work</description>
      <pubDate>Thu, 03 Mar 2005 07:24:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496805#M704866</guid>
      <dc:creator>Paolo Gilli</dc:creator>
      <dc:date>2005-03-03T07:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496806#M704867</link>
      <description>Anil,&lt;BR /&gt;can you do write a short example about your suggestion? May be the original string is too long and I not understand what you write.&lt;BR /&gt;Thanks&lt;BR /&gt;Paolo</description>
      <pubDate>Thu, 03 Mar 2005 08:16:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496806#M704867</guid>
      <dc:creator>Paolo Gilli</dc:creator>
      <dc:date>2005-03-03T08:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496807#M704868</link>
      <description>Hi Fred,&lt;BR /&gt;your suggestion:&lt;BR /&gt;find /pippo/* -prune -type f -name "DC*.DAT*" -mtime +45&lt;BR /&gt;works good as command line but not works if executed in a shell script</description>
      <pubDate>Thu, 03 Mar 2005 08:47:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496807#M704868</guid>
      <dc:creator>Paolo Gilli</dc:creator>
      <dc:date>2005-03-03T08:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: capture exit code of function inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496808#M704869</link>
      <description>Hi to all,&lt;BR /&gt;hire how I solved the problem. Hope this will be useful.&lt;BR /&gt;Best regards&lt;BR /&gt;Paolo&lt;BR /&gt;&lt;BR /&gt;for MONTHTOCHECK in `(find $BACKUPDIR -path "$BACKUPDIR/*" -prune -name  "DC*.DAT*" -type f -mtime $ONLINEDAYS;echo $?&amp;gt;RES0)|(sed s/.&lt;BR /&gt;*DC/DC/;echo $?&amp;gt;RES1)|(sort -d;echo $?&amp;gt;RES2) |(awk '{ printf( substr($1,3,6)"\n" ); }';echo $?&amp;gt;RES3) |(uniq -WQ ;echo $?&amp;gt;RES4)`&lt;BR /&gt;do&lt;BR /&gt;        echo $MONTHTOCHECK&lt;BR /&gt;done&lt;BR /&gt;# now I can use the retcodes store in RES*. #for example:&lt;BR /&gt;cat RES0&lt;BR /&gt;cat RES1&lt;BR /&gt;cat RES2&lt;BR /&gt;cat RES3&lt;BR /&gt;cat RES4</description>
      <pubDate>Mon, 07 Mar 2005 05:24:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/capture-exit-code-of-function-inside-for-loop/m-p/3496808#M704869</guid>
      <dc:creator>Paolo Gilli</dc:creator>
      <dc:date>2005-03-07T05:24:56Z</dc:date>
    </item>
  </channel>
</rss>

