![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exit Status within sudo su - $user | quigley007 | Shell Programming and Scripting | 7 | 07-29-2008 09:37 AM |
| handling maximum number characters in an input file | chrysSty | UNIX and Linux Applications | 1 | 05-12-2008 11:19 AM |
| Bourne Shell: Special characters Input Prevention | totziens | Shell Programming and Scripting | 37 | 04-23-2008 05:05 AM |
| Disallowing certain characters from user input | paqman | Shell Programming and Scripting | 1 | 08-09-2007 06:44 PM |
| Getting user input | stevefox | Shell Programming and Scripting | 3 | 02-16-2007 02:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
exit script if user input not four characters
#!/usr/bin/bash
###script to input four characters. wxyz echo "input first string" read instring1 echo "input second string" read instring2 ## echo "first string is:" $instring1 echo "second string is:" $instring2 ##IF instring1 or instring2 are NOT 4 characters (xxxx) , exit 1. ##how?? If it is any easier, the four input characters "should" be numbers, like 0032 and 0198, or 2359 and 0900 , but I'd settle for trusting that the user knows to input digits and not alphas.... |
|
|||||
|
Code:
read -penter:\
case $REPLY in
*[^0-9]* | "" ) printf "invalid number\n"; exit 1;;
???? ) printf "ok, let's go\n";;
* ) printf "wrong length\n"; exit 2;;
esac
P.S. Actually, this is sufficient: Code:
read -penter:\
case $REPLY in
[0-9][0-9][0-9][0-9] )
printf "ok, let's go\n";;
* )
printf "invalid number\n"
exit 1;;
esac
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|