Results 1 to 2 of 2
Hi,
im rather new to linux, trying to get my head around scripting.
i have made a shell script. i am trying to make a script that take in a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-01-2012 #1Just Joined!
- Join Date
- Nov 2012
- Posts
- 2
shell script help to a newbie
Hi,
im rather new to linux, trying to get my head around scripting.
i have made a shell script. i am trying to make a script that take in a date (DATE_TO_RUN) and find what day of week the date is.
what i need help with is to get the $DAYOFWEEK variable assigned with the value from printf("%d\n", (NF == 7 || FNR!=3) ? i-1 : i+(6-NF))
How to do this? Thanx, all help appriciated.
By running this script i get this output:Code:#!/bin/bash DATE_TO_RUN='2012-11-05' eval $(echo "${DATE_TO_RUN}" | nawk -F- '{printf("year=%s month=%s day=%s\n", $1, $2, $3)}') echo "year->[${year}] month->[${month}] day->[${day}]" DAYOFWEEK=-1 cal "${month}" "${year}" | nawk -v day="${day}" ' FNR > 2 { for(i=1; i <= NF; i++) if ( $i == day) { printf("%d\n", (NF == 7 || FNR!=3) ? i-1 : i+(6-NF)) exit } } ' echo "The date: " $DATE_TO_RUN " is day of week " $DAYOFWEEK
Want to have been:Code:year->[2012] month->[11] day->[05] 1 The date: 2012-11-05 is day of week -1
Code:year->[2012] month->[11] day->[05] 1 The date: 2012-11-05 is day of week 1
- 11-01-2012 #2Linux Newbie
- Join Date
- Nov 2012
- Posts
- 135
hi,
couldn't you rely on `date'?
Code:d2run="2012-11-05" date -d "$d2run" +%u 1


Reply With Quote
