LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-17-2006, 05:35 AM   #16
kb100
Member
 
Registered: Aug 2006
Posts: 43

Original Poster
Rep: Reputation: 15
scripting


This is the code i have inputted but it still doesn work!! Help me pls!!!

thanks



echo "Enter your birth year. Example: 1900 :"
read year
echo "Enter your birth month. Example: 06"
read month
monthyearnow=$(date '+%Y')
monthnow=$(date '+%m')
agey=$(expr $yearnow - $year)
agem=$(expr $monthnow - $month)
if [ $agem -lt 0 ] ; then
agem=$(expr $monthnow - $month + 12)
else
agem=$(expr $monthnow - $month)
fi
echo "You are $agey years and $agem months old!"
 
Old 08-17-2006, 06:41 AM   #17
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Code:
monthyearnow=$(date '+%Y')
should be
yearnow=$(date '+%Y')
Code:
#!/bin/bash

read -p "Enter your birth year. Example: 1900 :  " year
read -p "Enter your birth month. Example: 06    "  month

yearnow=$(date '+%Y')
monthnow=$(date '+%m')
agey=$(expr $yearnow - $year)
agem=$(expr $monthnow - $month)

if [ $agem -lt 0 ] ; then
   agem=$(expr $monthnow - $month + 12)
else
   agem=$(expr $monthnow - $month)
fi
echo "You are $agey years and $agem months old!"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
scripting help please deepsix Programming 10 09-08-2005 07:49 PM
Looking for scripting Help steve_f60 Linux - General 3 03-22-2005 12:45 PM
scripting bforest Linux - Newbie 4 05-11-2004 02:45 AM
Scripting Askari Programming 1 12-09-2003 09:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration