Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I'm a total newbie and have this guessing game assignment. I have it done for the most part, but my problem is seconds. I'm supposed to use the seconds ...
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    2

    [SOLVED] Help with seconds in a guessing game

    Hi, I'm a total newbie and have this guessing game assignment. I have it done for the most part, but my problem is seconds. I'm supposed to use the seconds from the date as my random number, then have it say if it's higher or lower. The way I did it was using
    number=$(date | cut -c 18-19)

    The problem is that when the number is low, under 10, you have to enter 01-09, instead of just 1-9. I know there is a date command that is supposed to use the seconds, with the %S but I don't know to write it? Here is what I have written.


    #!/bin/bash
    # A number guessing game
    number=$(date | cut -c 18-19)
    guess=1
    echo "Guess a number between 0 and 59:"
    read numberent
    # start loop
    while [ $numberent != $number ]
    do echo $numberent $number
    if test $numberent -gt $number
    then
    echo "Too large, try again:"
    else
    echo "Too small, try again:"
    # this exits the while loop
    fi
    read numberent
    let guess=guess+1
    done
    echo "You are a winner, it took $guess guesses"

  2. #2
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    1,946
    Do you mean the unix timestamp, second from 0101-1970: date +%s
    Don't know how you would use it in your script but that output seconds from that date like: linux-cjkf ~]$ date +%s
    1291693235

  3. #3
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    658
    Sorry guys, homework questions are against the forum rules
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  4. #4
    Just Joined!
    Join Date
    Dec 2010
    Posts
    2

    Can understand but I had the whole thing done

    I can understand not answering if I was asking for the whole script, but I had it done except for one thing that was working, but just not how I wanted.

    The answer though I found was date +%S but you have to add `date +%S` and then you can enter 1-9 instead of 01-09.

Posting Permissions

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