Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Bourne shells like <code>sh</code> and <code>bash</code> don't have GOTO statements. It's <a href="http://en.wikipedia.org/wiki/Considered_harmful" rel="nofollow">considered harmful</a>. </p> <p>Instead, use structured flow control like if statements:</p> <pre><code>echo "Enter the number to divide (dividend) (enter 999 to quit):" read numberOne if [ "$numberOne" -ne 999 ] then echo "Enter the number to divide (divisor) (enter 999 to quit):" read numberTwo while [ "$numberOne" -ne '999' ] &amp;&amp; [ "$numberTwo" -ne '999' ] do while [ "$numberTwo" -eq 0 ] do echo "You cannot divide by 0, please enter another number:" read numberTwo done RESULT=$(echo "$numberOne/$numberTwo" | bc -l) echo $numberOne / $numberTwo = $RESULT echo $numberOne / $numberTwo = $RESULT &gt;&gt; results.txt echo "Enter the number to divide (dividend) (enter 999 to quit):" read numberOne if [ "$numberOne" -ne 999 ] then echo "Enter the number to divide (divisor) (enter 999 to quit):" read numberTwo fi done fi counter=1 totalCount=0 temporal=0 while [ "$counter" -lt '101' ] do temporal=$( expr $counter % 5) echo $counter MOD 5 = $temporal echo $counter MOD 5 = $temporal &gt;&gt; results.txt totalCount=$(echo "$totalCount+$temporal" | bc -l) counter=$(echo "$counter+1" | bc -l) done average=$(echo "$totalCount/100" | bc -l) echo The average of all the MODs is $average &gt;&gt; results.txt </code></pre> <p>It may seem more awkward than one simple goto, but as you take advantage of more structured control flow, the code gets easier to read and follow:</p> <pre><code>readNumber() { local number read -p "$1" number [ "$number" -ne 999 ] &amp;&amp; echo "$number" } while one=$(readNumber "Enter dividend or 999 to quit: ") &amp;&amp; \ two=$(readNumber "Enter divisor or 999 to quit: ") do echo "$one / $two = $(echo "$one / $two" | bc -l)" | tee results.txt done </code></pre> <p>This keeps asking for numbers to divide, until the user enters 999 for either of them. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload