please help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers please help
# 1  
Old 05-24-2007
please help

How do i write a shell script to check if a date entered is a saturday?
# 2  
Old 05-24-2007
Check the manual for the date command. Really depends on the format the date is inputed. the '%w' variable for date formating returns the 'day of the week' where 0 is sunday and 6 is Saturday.

In general you can use something like the following.

Code:
echo "Please enter a date YYYY/MM/DD"
read date

day=`date -d $date +"%w"`

if [ $day -eq 6 ]
then
  echo "$date is a Saturday"
else
  echo "$date is NOT a Saturday"
fi

# 3  
Old 05-24-2007
the date format is supposed to be yyyy mm dd
# 4  
Old 05-24-2007
Quote:
Originally Posted by newbie130
the date format is supposed to be yyyy mm dd
Code:
echo "2007 01 06" | awk '$NF == 6 { print "yes: saturday" }'

# 5  
Old 05-24-2007
thanx guys. i'ld give it a shot
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question