<?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: stuck with run-on while-loop in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522336#M728610</link>
    <description>Mark-&lt;BR /&gt;&lt;BR /&gt;The done is later on, after the last do option.  Switching the first do to a done would end the loop after getting the variable, I think.  It would make the while kinda useless.</description>
    <pubDate>Fri, 27 Apr 2001 17:20:28 GMT</pubDate>
    <dc:creator>Mark Vollmers</dc:creator>
    <dc:date>2001-04-27T17:20:28Z</dc:date>
    <item>
      <title>stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522329#M728603</link>
      <description>Hello everyone,&lt;BR /&gt;&lt;BR /&gt;I need help with the while-loop.  I'd been at it for the last 2 days and I'm running out of steam and patient.  This is my code:&lt;BR /&gt;&lt;BR /&gt;while echo "Choose options: A) do this&lt;BR /&gt;             B) do that&lt;BR /&gt;             C) do whatever&lt;BR /&gt;             X) exit"&lt;BR /&gt;read resp&lt;BR /&gt;do&lt;BR /&gt;   if [ "$resp" = "A" ];&lt;BR /&gt;   then&lt;BR /&gt;       do this ...&lt;BR /&gt;   fi&lt;BR /&gt;&lt;BR /&gt;..... the same with other options&lt;BR /&gt;&lt;BR /&gt;   if [ "$resp" = "X" ];&lt;BR /&gt;   then&lt;BR /&gt;       exit 0&lt;BR /&gt;   fi&lt;BR /&gt;done &lt;BR /&gt;scripting...&lt;BR /&gt;scripting...&lt;BR /&gt;....&lt;BR /&gt;echo "End of Script"&lt;BR /&gt;&lt;BR /&gt;Here is my problem.  When I tested the script if I hit ENTER or SPACE the script returns me to the begin of the loop asking to pick one of the option - GREAT.  When I chose Option A the script goes into that section and perform its job - when the job is done the script is then jump BACK to the top of the while-loop.  It does not exit the while-loop and continue on with the script but just back to the while-loop.  It will only exit if I choose "X" but then the rest of the script is not run.  I had tried counter in the while-loop (i.e: &lt;BR /&gt;count=0&lt;BR /&gt;while [ "$resp" != "X" ] || [ "$count" = "0" ];&lt;BR /&gt;(this does not recogize by sh i.e shell only interpret : [ A != "X" .......-blank )&lt;BR /&gt;while [ "$resp" != "X" OR "$count" = "0" ]&lt;BR /&gt;do &lt;BR /&gt;....&lt;BR /&gt;...&lt;BR /&gt;count=1   (if job success)&lt;BR /&gt;count=0   (if job not success)&lt;BR /&gt;done&lt;BR /&gt;I tested this with "set -x" option to see how the shell interpret my command.  When I ran the script the while-loop looks like this&lt;BR /&gt; while [ A != "X" OR 0 = 0 ]&lt;BR /&gt; do &lt;BR /&gt;   ......&lt;BR /&gt;   count=1 (job is success)&lt;BR /&gt;AND the script goes back to the top of while-loop again (the shell show :&lt;BR /&gt; while [  != "X" OR 1 = 0 ]&lt;BR /&gt; do&lt;BR /&gt;   .....&lt;BR /&gt;   it waits here for me to choose X to exit or another option &lt;BR /&gt;&lt;BR /&gt;From the above I see that count return a value of 1 thus the while-loop should exit BUT it does not.  Please help, my patient tank is running pretty low.  Thank you in advance.&lt;BR /&gt;Thi</description>
      <pubDate>Fri, 27 Apr 2001 15:24:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522329#M728603</guid>
      <dc:creator>Thi Vu</dc:creator>
      <dc:date>2001-04-27T15:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522330#M728604</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;'break' will break-out of the loop.  'continue' will start the loop again.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 27 Apr 2001 15:35:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522330#M728604</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-04-27T15:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522331#M728605</link>
      <description>James is right about the break and continue commands to quit the loop.  I'm a little confused about how you have it set up, though.  It sounds like you want to select A, for example, and then quit the loop and run some other stuff, or B and then run the same stuff, etc.  X will end the script.  Why not use a 'case' statement instead, since this sounds like a normal menu?  You wouldn't have to worry about the looping.  Just a thought.&lt;BR /&gt;&lt;BR /&gt;Mark</description>
      <pubDate>Fri, 27 Apr 2001 15:48:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522331#M728605</guid>
      <dc:creator>Mark Vollmers</dc:creator>
      <dc:date>2001-04-27T15:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522332#M728606</link>
      <description>Hi again:&lt;BR /&gt;&lt;BR /&gt;See if this example helps you:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;echo "...enter choice..."&lt;BR /&gt;read  CHOICE&lt;BR /&gt;case $CHOICE in&lt;BR /&gt;  0 )&lt;BR /&gt;  echo "&amp;gt; doing 0 &amp;lt;"&lt;BR /&gt;  break&lt;BR /&gt;  ;;&lt;BR /&gt;  1 )&lt;BR /&gt;  echo "&amp;gt; doing 1 &amp;lt;"&lt;BR /&gt;  continue&lt;BR /&gt;  ;;&lt;BR /&gt;  * )&lt;BR /&gt;  echo "&amp;gt; doing something else &amp;lt;"&lt;BR /&gt;  ;;&lt;BR /&gt;esac&lt;BR /&gt;done&lt;BR /&gt;echo "...continuing after loop..."&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 27 Apr 2001 15:54:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522332#M728606</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-04-27T15:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522333#M728607</link>
      <description>Here's one tip, do not use the ; after the if statement, that might be causing the loop.</description>
      <pubDate>Fri, 27 Apr 2001 16:25:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522333#M728607</guid>
      <dc:creator>Jim Moffitt_1</dc:creator>
      <dc:date>2001-04-27T16:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522334#M728608</link>
      <description>while echo "Choose options: A) do this &lt;BR /&gt;B) do that &lt;BR /&gt;C) do whatever &lt;BR /&gt;X) exit" &lt;BR /&gt;read resp &lt;BR /&gt;do &lt;BR /&gt;if [ "$resp" = "A" ]; &lt;BR /&gt;then &lt;BR /&gt;do this ... &lt;BR /&gt;fi &lt;BR /&gt;Agree with the above -- case would be preferable to if.&lt;BR /&gt;Also -- that "do" after read resp is really a "done", no?</description>
      <pubDate>Fri, 27 Apr 2001 16:46:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522334#M728608</guid>
      <dc:creator>Mark Fenton</dc:creator>
      <dc:date>2001-04-27T16:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522335#M728609</link>
      <description>I think the done should be after fi</description>
      <pubDate>Fri, 27 Apr 2001 16:55:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522335#M728609</guid>
      <dc:creator>Jim Moffitt_1</dc:creator>
      <dc:date>2001-04-27T16:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522336#M728610</link>
      <description>Mark-&lt;BR /&gt;&lt;BR /&gt;The done is later on, after the last do option.  Switching the first do to a done would end the loop after getting the variable, I think.  It would make the while kinda useless.</description>
      <pubDate>Fri, 27 Apr 2001 17:20:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522336#M728610</guid>
      <dc:creator>Mark Vollmers</dc:creator>
      <dc:date>2001-04-27T17:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: stuck with run-on while-loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522337#M728611</link>
      <description>Thank you for all of the responses.  I did try the CASE for my problem above but it did not do what I wanted it to do (i.e: if user hit enter by mistake the script EXIT with the CASE - I wanted the script to remain at the menu until he/she choses X to exit).  The "break" works great for me.  Again, thank you everyone for your help.&lt;BR /&gt;&lt;BR /&gt;Thi</description>
      <pubDate>Mon, 30 Apr 2001 14:33:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/stuck-with-run-on-while-loop/m-p/2522337#M728611</guid>
      <dc:creator>Thi Vu</dc:creator>
      <dc:date>2001-04-30T14:33:27Z</dc:date>
    </item>
  </channel>
</rss>

