1
votes

I am new to shell scripting. I want to write a shell script to get the date from user from the terminal in format yyyy-mm-dd and use that date as start date to get the revision changes made in svn repository for a particular date range.

My script is:

echo "Date"
echo "Enter year"
read Y
echo "Enter month"
read M
echo "Enter Date"
read D
D1=`expr $D + 3`
svn log -r {$Y-$M-$D}:{$Y-$M-$D1} http://svn.abc.com/svn/trunk.

This is the script I have written.

I know I should use date function not sperately Y M D.
And also I want to list only revision numbers not full log messages as svn log command shows.

1

1 Answers

1
votes

I would use the date utility for verification:

while true; do
    read -p "Enter a date (YYYY-mm-dd): " user_date
    if date=$(date -d "$user_date" +%F); then 
        # user date was ok
        break
    fi
done
date3=$(date -d "$date + 3 days" +%F)
svn log -r "$date:$date3" ...

You really need to use date, especially to add 3 days: you don't want to end up with "2014-02-30"