0

I'M trying to write a small program that will validate weather or not a string is valid. Assuming that the date will always be 8 digits (12/21/2012) I need a function that will count the number of digits in a string. What I've got below is only returning "'is not 8 digits' even when I am inputing 8 digits.

! /bin/bash

This is the calender array for the DateValidation program

calender=(31 28 31 30 31 30 31 31 30 31 30 31)

read -p "Enter a date for validation: " Date

set the variable "LEN" to hold the lengh of the input number

LEN=$(echo ${Date})

if [ $LEN -lt 8 ]; then

echo "$Date' is 8 characters'"

else "$Date' is not 8 characters'"

fi

END

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by Watael
1

hi,

no need of a function, bash parameter substitution can do it:

read -p' enter date: ' Date
test ${#Date} -eq 8 || s=" not"
echo "$Date is$s 8 chars"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.