How to write a program in bash which draw a number

Discussion in 'Command Line' started by Shozda, Jun 10, 2013.

  1. Shozda

    Shozda New Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    i would like to write a program wchich draws a number on of 100 and than it wirte to user it's too much if its bigger than drawed number or it's to low if number (which wrote user) is lower.
    I have stomething like this but I have got errors:


    Code:
    num=`$((RANDOM/327))`
    echo „write a number from 0 -100”
    read type
    until  [ $num = $type ]
    do
    if [$num –lt $type]
    then echo “too much!”
    sleep 1
    clear
    echo “Try again!”
    read type
    esle if [$num –gt $type] then
    echo “too low!”
    sleep 1
    echo “Try again!”
    read type
    fi
    fi
    done
    well I get multiple errors. could anybodie help?
  2. arochester

    arochester Well-Known Member

    Messages:
    853
    Likes Received:
    273
    Trophy Points:
    63
  3. Shozda

    Shozda New Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Ok quite good working prog is:

    Code:
    type=$((RANDOM/327))
    until [ $num = $type ];
    do
    clear
    echo “give me number from 1-100”
    read num
    if [$num –lt $type]
    then echo -e “to low!”
    elif [$num –gt $type]
    then
    echo –e “to much!”
    fi
    sleep 1
    done
    however I have an error because it always pick up 0 (zero) I don't know why. Maybey it's fedora or sth.
  4. arochester

    arochester Well-Known Member

    Messages:
    853
    Likes Received:
    273
    Trophy Points:
    63
    As grail said "You mention about the user entering numbers in the range 0 - 100 in the script but then have used the number 327??? I am not sure I see the point here?"

    RANDOM % 100 + 1
  5. Mofei

    Mofei New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Code:
    if [ $num –lt $type ]
    In the shell, if statement must have spaces.

Share This Page