Re: case statement to validate input
From: laura_fairhead (laura_fairhead_at_INVALID.com)
Date: 10/13/03
- Next message: laura_fairhead: "Re: dev zero into dd varies in length"
- Previous message: Kevin Rodgers: "Re: Execute every command in script as regular user?"
- In reply to: John: "case statement to validate input"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 13 Oct 2003 15:21:56 +0000
In article <987ib.147337$bo1.8607@news-server.bigpond.net.au>, John wrote:
>Hi,
>
>I'm trying to validate input using:
>
>case "$answer" in
>[a-zA-Z][0-9a-zA-Z]\{7\}
>echo "Correct input";;
>*)
>echo "Incorrect input";;
>esac
>
>I'm expecting input to be a char followed by up to 7 chars or digits.
>
>Can anyone suggest were I'm failing?
There is no closing bracket to delimit the case pattern but more
importantly the pattern won't match what you want - case statements
take a shell pattern (similar to a filename pattern) not a regular
expression so the modifier \{7\} won't be recognised. (As a regular
expression this actually says a character followed by 7 digits and
not 'up to' as you state in your description)
You should write it out in full;
case $answer in
[a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]\
[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]) echo "Correct input";;
*) echo "Incorrect input";;
esac
Instead of 7 characters allowing a variable number from 0 to 7
would be;
case $answer in
?????????*|""|[!a-zA-Z]*|?*[!0-9a-zA-Z]*) echo "Incorrect Input";;
*) echo "Correct Input";;
esac
byefornow
l
>
>Thanks
>
>
>
-- echo alru_aafriehdab@ittnreen.tocm |sed 's/\(.\)\(.\)/\2\1/g'
- Next message: laura_fairhead: "Re: dev zero into dd varies in length"
- Previous message: Kevin Rodgers: "Re: Execute every command in script as regular user?"
- In reply to: John: "case statement to validate input"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|