<?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: Scripting question (exiting a while loop) in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442720#M769151</link>
    <description>Steve,&lt;BR /&gt;&lt;BR /&gt;Use 'break' to exit the loop, 'continue' to go back to the start.&lt;BR /&gt;&lt;BR /&gt;Both commands have a numeric argument which indicates which level of loop (for loops within loops).&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John</description>
    <pubDate>Tue, 05 Sep 2000 17:11:46 GMT</pubDate>
    <dc:creator>John Palmer</dc:creator>
    <dc:date>2000-09-05T17:11:46Z</dc:date>
    <item>
      <title>Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442717#M769148</link>
      <description>Hello everyone,&lt;BR /&gt;I'm writing a while loop that reads input from a file.  I then run some tests on the data.  If the tests pass then it should continue, but if they fail then I want to move to the next record.  I've tried putting a "done" statement in my "then" statement, but apparently it doesn't like that (I get an unexpected done error).  Any thoughts?&lt;BR /&gt;&lt;BR /&gt;Thanks ,&lt;BR /&gt;Steve</description>
      <pubDate>Tue, 05 Sep 2000 16:59:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442717#M769148</guid>
      <dc:creator>Steve Sauve</dc:creator>
      <dc:date>2000-09-05T16:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442718#M769149</link>
      <description>Steve:&lt;BR /&gt;&lt;BR /&gt;Use the "break" keyword....&lt;BR /&gt;&lt;BR /&gt;do a man on sh-posix for more details.&lt;BR /&gt;&lt;BR /&gt;cheers</description>
      <pubDate>Tue, 05 Sep 2000 17:02:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442718#M769149</guid>
      <dc:creator>Kofi ARTHIABAH</dc:creator>
      <dc:date>2000-09-05T17:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442719#M769150</link>
      <description>Steve,&lt;BR /&gt;&lt;BR /&gt;Use 'break' to exit the loop, 'continue' to go back to the start.&lt;BR /&gt;&lt;BR /&gt;Both commands have a numeric argument which indicates which level of loop (for loops within loops).&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John</description>
      <pubDate>Tue, 05 Sep 2000 17:11:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442719#M769150</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2000-09-05T17:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442720#M769151</link>
      <description>Steve,&lt;BR /&gt;&lt;BR /&gt;Use 'break' to exit the loop, 'continue' to go back to the start.&lt;BR /&gt;&lt;BR /&gt;Both commands have a numeric argument which indicates which level of loop (for loops within loops).&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John</description>
      <pubDate>Tue, 05 Sep 2000 17:11:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442720#M769151</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2000-09-05T17:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442721#M769152</link>
      <description>Use while (equation, argument)&lt;BR /&gt;    do (command)&lt;BR /&gt;    done.</description>
      <pubDate>Tue, 05 Sep 2000 17:12:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442721#M769152</guid>
      <dc:creator>CHRIS_ANORUO</dc:creator>
      <dc:date>2000-09-05T17:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442722#M769153</link>
      <description>Follow Kofi's advice:&lt;BR /&gt;YOu will have to use in your while loop with if statements the words break or continue&lt;BR /&gt;example of while syntax:&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;  echo Enter filename&lt;BR /&gt;  read FILE&lt;BR /&gt;  if [ "$FILE" = "" ]&lt;BR /&gt;   then&lt;BR /&gt;     break&lt;BR /&gt;   fi&lt;BR /&gt;  echo "Edit : " $FILE " ?"&lt;BR /&gt;   read AA&lt;BR /&gt;   if [ "$AA" = "" -o "$AA" = no ]&lt;BR /&gt;    then&lt;BR /&gt;       continue&lt;BR /&gt;    else&lt;BR /&gt;        rm $FILE&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Sep 2000 17:18:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442722#M769153</guid>
      <dc:creator>Victor BERRIDGE</dc:creator>
      <dc:date>2000-09-05T17:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442723#M769154</link>
      <description>I meant vi $FILE&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Very hard trying to be multitasking, you know being at the phone on rm subject, people calling you from outside and trying to reply all at the same time...&lt;BR /&gt;Sorry</description>
      <pubDate>Tue, 05 Sep 2000 17:36:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442723#M769154</guid>
      <dc:creator>Victor BERRIDGE</dc:creator>
      <dc:date>2000-09-05T17:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442724#M769155</link>
      <description>Thanks for the advice guys, but it still doesn't seem to be working.  Apparently the script is just ignoring the break/continue command. Could it be the fact that a function is calling the break/continue while the loop is in the main body?&lt;BR /&gt;Ex.&lt;BR /&gt;test()  {&lt;BR /&gt;if (logical test)&lt;BR /&gt; then&lt;BR /&gt;  break&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;#main body&lt;BR /&gt;while read xyz&lt;BR /&gt; do&lt;BR /&gt; test;&lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt;Any thoughts?&lt;BR /&gt;Thanks for the help,&lt;BR /&gt;Steve</description>
      <pubDate>Tue, 05 Sep 2000 17:37:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442724#M769155</guid>
      <dc:creator>Steve Sauve</dc:creator>
      <dc:date>2000-09-05T17:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442725#M769156</link>
      <description>Thanks for the advice guys, but it still doesn't seem to be working.  Apparently the script is just ignoring the break/continue command. Could it be the fact that a function is calling the break/continue while the loop is in the main body?&lt;BR /&gt;Ex.&lt;BR /&gt;test()  {&lt;BR /&gt;if (logical test)&lt;BR /&gt; then&lt;BR /&gt;  break&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;#main body&lt;BR /&gt;while read xyz&lt;BR /&gt; do&lt;BR /&gt; test;&lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt;Any thoughts?&lt;BR /&gt;Thanks for the help,&lt;BR /&gt;Steve</description>
      <pubDate>Tue, 05 Sep 2000 17:37:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442725#M769156</guid>
      <dc:creator>Steve Sauve</dc:creator>
      <dc:date>2000-09-05T17:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442726#M769157</link>
      <description>Thanks for the advice guys, but it still doesn't seem to be working.  Apparently the script is just ignoring the break/continue command. Could it be the fact that a function is calling the break/continue while the loop is in the main body?&lt;BR /&gt;Ex.&lt;BR /&gt;test()  {&lt;BR /&gt;if (logical test)&lt;BR /&gt; then&lt;BR /&gt;  break&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;#main body&lt;BR /&gt;while read xyz&lt;BR /&gt; do&lt;BR /&gt; test;&lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt;Any thoughts?&lt;BR /&gt;Thanks for the help,&lt;BR /&gt;Steve</description>
      <pubDate>Tue, 05 Sep 2000 17:38:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442726#M769157</guid>
      <dc:creator>Steve Sauve</dc:creator>
      <dc:date>2000-09-05T17:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442727#M769158</link>
      <description>Thanks for the advice guys, but it still doesn't seem to be working.  Apparently the script is just ignoring the break/continue command. Could it be the fact that a function is calling the break/continue while the loop is in the main body?&lt;BR /&gt;Ex.&lt;BR /&gt;test()  {&lt;BR /&gt;if (logical test)&lt;BR /&gt; then&lt;BR /&gt;  break&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;#main body&lt;BR /&gt;while read xyz&lt;BR /&gt; do&lt;BR /&gt; test;&lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt;Any thoughts?&lt;BR /&gt;Thanks for the help,&lt;BR /&gt;Steve</description>
      <pubDate>Tue, 05 Sep 2000 17:38:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442727#M769158</guid>
      <dc:creator>Steve Sauve</dc:creator>
      <dc:date>2000-09-05T17:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442728#M769159</link>
      <description>Steve:&lt;BR /&gt;&lt;BR /&gt;If, in your last post, the objective is to exit the function at large, change the break to a return.  You will exit the loop and the function at that point.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 05 Sep 2000 17:40:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442728#M769159</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2000-09-05T17:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442729#M769160</link>
      <description>Hi steve,&lt;BR /&gt;1) you have no condition to your while:&lt;BR /&gt;while &lt;LOOP termination="" condition=""&gt;&lt;BR /&gt;do&lt;BR /&gt;..&lt;BR /&gt;then you should put your read in the loop&lt;BR /&gt;while..&lt;BR /&gt;do&lt;BR /&gt; read &lt;INPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt;your test&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;/INPUTFILE&gt;&lt;/LOOP&gt;</description>
      <pubDate>Tue, 05 Sep 2000 17:56:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442729#M769160</guid>
      <dc:creator>Victor BERRIDGE</dc:creator>
      <dc:date>2000-09-05T17:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442730#M769161</link>
      <description>Second thought,&lt;BR /&gt;I wonder if you should not try to use continue!&lt;BR /&gt;For continue tells the shel to ignore the remainder of the loop and return to the beginning of your loop.&lt;BR /&gt;So you should write somthing like&lt;BR /&gt;while..&lt;BR /&gt;do&lt;BR /&gt;read..&lt;BR /&gt;if&lt;BR /&gt;then&lt;BR /&gt; continue&lt;BR /&gt;fi&lt;BR /&gt;more treatment&lt;BR /&gt;..&lt;BR /&gt;done</description>
      <pubDate>Tue, 05 Sep 2000 18:10:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442730#M769161</guid>
      <dc:creator>Victor BERRIDGE</dc:creator>
      <dc:date>2000-09-05T18:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442731#M769162</link>
      <description>Steve:&lt;BR /&gt;&lt;BR /&gt;The break needs to be in the loop.  Do something like:&lt;BR /&gt;&lt;BR /&gt;while read X&lt;BR /&gt;do&lt;BR /&gt;  echo "I saw $X"&lt;BR /&gt;  if [ "$X" = "ok" ]&lt;BR /&gt;  then&lt;BR /&gt;    break #...quit reading...exit the loop!&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 05 Sep 2000 18:35:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442731#M769162</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2000-09-05T18:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442732#M769163</link>
      <description>Thanks for the help everyone.  After some testing it seems that the continue statement doesn't work from inside a function.  The "return" statement also doesn't really help since the function only tests the input and doesn't modify it (that's the next function).  The tests I ran are below.  The script that has no functions works fine, where as the one with the function ignores the test.  Unless someone has another thought, I'll just modify my script to include the test in the main body.  Thanks for the help, &lt;BR /&gt;Steve&lt;BR /&gt;&lt;BR /&gt;# This one works&lt;BR /&gt;while read first last loc&lt;BR /&gt; do&lt;BR /&gt;  if [ "$last" = "" ]&lt;BR /&gt;   then&lt;BR /&gt;    continue &lt;BR /&gt;  fi&lt;BR /&gt;echo $first $last&lt;BR /&gt;done &amp;lt; names&lt;BR /&gt;&lt;BR /&gt;# This one don't&lt;BR /&gt;tst() {&lt;BR /&gt; if [ "$last" = "" ]&lt;BR /&gt;  then &lt;BR /&gt;   continue &lt;BR /&gt; fi&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;while read first last loc&lt;BR /&gt; do&lt;BR /&gt;tst;&lt;BR /&gt;echo $first $last&lt;BR /&gt;done &amp;lt; names</description>
      <pubDate>Tue, 05 Sep 2000 19:01:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442732#M769163</guid>
      <dc:creator>Steve Sauve</dc:creator>
      <dc:date>2000-09-05T19:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question (exiting a while loop)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442733#M769164</link>
      <description>As you've discovered, continue and break will not work in a function (not when the do loop is outside it anyway). The way around this if you want to keep the function is to get it to return a value to indicate whether or not to continue.&lt;BR /&gt;&lt;BR /&gt;Your example with a function:-&lt;BR /&gt;&lt;BR /&gt;tst() { &lt;BR /&gt;if [ "$last" = "" ] &lt;BR /&gt;then return 0&lt;BR /&gt;else return 1 &lt;BR /&gt;fi &lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;while read first last loc &lt;BR /&gt;do &lt;BR /&gt;if tst;&lt;BR /&gt;then continue&lt;BR /&gt;fi&lt;BR /&gt;echo $first $last &lt;BR /&gt;done &amp;lt; names</description>
      <pubDate>Tue, 05 Sep 2000 21:03:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-exiting-a-while-loop/m-p/2442733#M769164</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2000-09-05T21:03:03Z</dc:date>
    </item>
  </channel>
</rss>

