Does Anyone know....


Results 1 to 2 of 2

Thread: Does Anyone know....

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    2

    Red face Does Anyone know....

    ....how to use basic arithmetic options in a case state statement and then loop them with say, a "while" loop? Please be gentle as I am definitely a newbie.

    Example: Very simple option "case statement" for these alltogether.

    sum=$((num1 + num2))
    diff=$((num1 - num2))
    prod=$((num1 *\ num2))
    quot=$((num1 / num2))

    and then "while" looped.

    thanks,

    joe.

  2. #2
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    This looks like a homework to me.

    Don't do much Bash script myself by a quick Google with "while in BASH" turns up
    Code:
             #!/bin/bash 
             COUNTER=0
             while [  $COUNTER -lt 10 ]; do
                 echo The counter is $COUNTER
                 let COUNTER=COUNTER+1 
             done
    You need a counter of some sort to test when to stop as your script is just playing with two numbers without any ending.

    If you insert your text into the middle of the above, say after the line echo, your script will be executed 10 times when $COUNTER exceed 10.
    Last edited by saikee; 08-28-2013 at 09:44 AM.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •