Find the answer to your Linux question:
Results 1 to 3 of 3
Hello all! I am new to linux and I am trying to learn bash scripts. I would like to be able to ask the user for their birthday and then ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    1

    Compare date to variables in bash


    Hello all! I am new to linux and I am trying to learn bash scripts. I would like to be able to ask the user for their birthday and then compare that to the system date. I would like it to display a message if it's their birthday, and a different one if it's not. It doesn't have to be this exactly, it's just something I was trying, so something similar would work, too. Basically, I just wanna compare user inputs to the date.

    Also, is there a way to insert a pause between messages? ie, echo 1, [pause 1 second], echo 2, etc.

    In case it matters, I'm running SLES 10. Thanks in advance!

  2. #2
    Linux Newbie
    Join Date
    May 2007
    Posts
    106
    Quote Originally Posted by benjamines View Post
    Also, is there a way to insert a pause between messages? ie, echo 1, [pause 1 second], echo 2, etc.

    In case it matters, I'm running SLES 10. Thanks in advance!
    sleep 5

    This will cause your script to pause for 5 seconds before proceeding. Read 'man sleep'.

    As to your first question, there are literally thousands of ways to do this. Search google for a shell scripting tutorial.

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Posts
    3

    Post sol a bit late maybe will be useful for someone else

    #------------------
    b=`date +%D`
    echo -e "Enter your birthday (format mm/dd/yy 06/04/09 ) \c"
    read a
    if [ "$a" = "$b" ]
    then
    # do whatever you like
    echo "happy birthday"
    else
    #code block
    echo "Better wait for a few more days "
    fi



Posting Permissions

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