Tag Info

New answers tagged

1

This method treats input as a string then parses and tests it for proper formatting. In this form, I have it also checking if the fields in the date are correct, but you can remove those conditionals if you don't need them. #!/bin/bash echo -n "Enter the date as YYYYMMDD >" read date if [ ${#date} -eq 8 ]; then year=${date:0:4} month=${date:4:2} ...


1

You might like the option to accept many formats and convert them to standard form; the date command can help: $ day=$(unset day; until date -d "${day:-XXX}" '+%Y%m%d' 2>/dev/null do read -p "Which day? " day done) Which day? Which day? weds Which day? friday $ echo $day 20150508



Top 50 recent answers are included