Link to home
Create AccountLog in
Avatar of megashares
megashares

asked on

How to prevent some case when input datetime ?

This code below is check leap year and invalid day completed.
 But I have some problem.I try to make an trap.People insert blank space when enter day, and program not accept and sad input invalid day again ( not blank space).  I try any time it not worked :|. I new to shell scripting. Please help
#!/bin/bash
result="FALSE"
while [ $result = "FALSE" ]
do 
echo -n "Enter day(mm/dd/yyyy): " 
read datetime
if date --date="$datetime" >/dev/null
then
result="TRUE"
else 
result="FALSE"
fi
done

Open in new window

Avatar of Tintin
Tintin

I can't reproduce your problem.  I've tried entering dates with all sorts of spaces and it works fine.

Can you please show us an example.
Avatar of megashares

ASKER

Enter day(mm/dd/yyyy): I press "enter button" or spacebar and enter. I out my program. I want when someone press some thing like this my program will not accept and notice to enter an valid value again
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
don't see a reason for a delete, valid suggestions are there
could you please explain?