starlite79
Technical User
Hi all,
This relates to the closed thread thread822-1501717.
I've modified the script to get files in a range of two dates that are supplied on the command line while running the script. I want to test that both $1 and $2 are in the format MM/DD/YYYY. This is what I have so far:
However, this syntax does not work. date gives an error that there is an extra operand. The program does work if both dates are in the correct format, but I want the else statement to execute if either or both the arguments are not given as MM/DD/YYYY as needed by the rest of the script.
This relates to the closed thread thread822-1501717.
I've modified the script to get files in a range of two dates that are supplied on the command line while running the script. I want to test that both $1 and $2 are in the format MM/DD/YYYY. This is what I have so far:
Code:
# Define a variable for the analysis files. Earliest analysis file for 2008
# is from January 1, 2008. Get two date string arguments from the command
# line (i.e. $1 $2). Dates must be in MM/DD/YYYY format.
date1="${1}"
date2="${2}"
# Get dates from standard input
if [ -n $(date +%m/%d/%Y $date1) ] && [ -n $(date +%m/%d/%Y $date2) ]; then
echo "dates are " $date1 $date2
else
echo "need to add two dates to input line "
echo " such as 08/08/2008 08/09/2008 "
echo " in MM/DD/YYYY format. "
exit
fi
However, this syntax does not work. date gives an error that there is an extra operand. The program does work if both dates are in the correct format, but I want the else statement to execute if either or both the arguments are not given as MM/DD/YYYY as needed by the rest of the script.