So here, as I am of French speaking language, not sure what I should understand:
Birthday = anniversary or day of birth?
It changes things as it anniversary, year is current and so you display the day of birthday this year and coming 3-4.
the case of 29.02 is pending... but if you dont need to give the year, the person born on that day usually choose another day for birthday for all administrative purpose and so you could consider the date as " Not being treated "
in other word the person born on that day knows very well the coming issue and if he enters 29.02 it is just to see what happens so displaying Not being treated is, a way to say you know the problem and it is at that person to give the answer: on what day do you celebrate when not leap year...
So your task is if you want to use that shell script, as I did, you will have to write a bit of code before or more precisely in between the variables declaration and input - and - the awk lines:
That is to write a test on 29.02, if you are to enter the year then your test need to treat the leap year ( if leap year, if month 02 if day 29... now you have it all)
To not make a fool of you, I would test year in between 1901-2099 and display Year=1901-2099 to avoid complicated calculation to find leap year, in between those 2 values its dead easy...
When you are into writing script and you want to be sure what is going on, display using echo every bit of process, this is the beginning of debugging tricks
my result: look at what is displayed...
vbes-MacBook-Pro:~ $ ./dow
Enter YOUR DATE: (between 1901-2099)
Follow this[yearmonthdate] format:
19970229
D=29 M=02 Y=1997
Valid=1
not a leap year
month=02, Feb
invalid date
vbes-MacBook-Pro:~ $
vbes-MacBook-Pro:~ $ ./dow
Enter YOUR DATE: (between 1901-2099)
Follow this[yearmonthdate] format:
19970228
D=28 M=02 Y=1997
Valid=1
not a leap year
month=02, Feb
1997 = Friday
1998 = Saturday
1999 = Sunday
2000 = Monday
2001 = Wednesday
vbes-MacBook-Pro:~ $ ./dow
Enter YOUR DATE: (between 1901-2099)
Follow this[yearmonthdate] format:
20000229
D=29 M=02 Y=2000
Valid=0
Leap Year
2000 = Tuesday
vbes-MacBook-Pro:~ $
And to get you working and showing I did use the script you gave
Here is with blanks the part of the script with my test that produces above output, up to you to figure out what is missing, but you see my usage of echo... or you write your own test following your ideas ( yes many solutions...)
I don't write bash shell to be the most portable possible, so you will see what many consider obsolete writing, feel free to correct, it will show you have read and understood what is going on if you can rewrite in more current style
#!/bin/sh
echo "Enter YOUR DATE: (between 1901-2099)"
echo "Follow this[yearmonthdate] format:"
read d
day=${d#??????}
temp=${d#????}
month=${temp%??}
year=${d%????}
let i=0 # Used after for displaying the 4 years
echo D=$day" "M=$month" "Y=$year
let Valid=(calculation to find leap year)
echo Valid=$Valid
if [ $Valid ...... ]
then
echo " not a leap year"
if [ "$month" .... ]
then
echo month=$month, Feb
if [ $day ... ]
then
echo invalid date
exit 2
fi
fi
else
echo "Leap Year"
let i=4
fi
Being a noob is no excuse to not try to progress and work, so now the next thing we want to see is the test completed or your test proposal with its output, all published here, so we can validate your work or correct you if still some issues but I believe there should not be because you have it all, in order to continue further.
Then next step ( only once this one is successful... ):
Are you to use awk etc.. or as suggested using date is accepted ( if you have GNU date...)?