Sponsored Content
Full Discussion: BASH validate user input
Top Forums UNIX for Dummies Questions & Answers BASH validate user input Post 302338274 by 602chrislys on Monday 27th of July 2009 11:41:52 AM
Old 07-27-2009
BASH validate user input

Hey, im trying to validate a user input and need some help. The input needs to be just a single letter. Im using a case to so this eg:

Code:
read answer
case $answer in
     [A-Za-z]*) echo "OK"
        ;;
     [0-9]*) echo "This is a number"
                read answer
        ;;
        *)   echo "Please enter a letter ! !"
              read answer
        ;;
esac

I need to stop multiple letters and repeat letters being entered. Any ideas?? Thanks for any help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

validate input from user for file name

Hello, This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name. The file name should not have any of the following characters ~`!@#$%^&*()_-+={|\:;"'<,>.?/ Further the response should not have any... (2 Replies)
Discussion started by: jerardfjay
2 Replies

2. Shell Programming and Scripting

Bash : how do i check the user input and make sure is only chracter or only number ?

Bash : how do i check the user input and make sure is only character or only number ? (7 Replies)
Discussion started by: CheeSen
7 Replies

3. Shell Programming and Scripting

BASH Varible nesting and user input

Well, I think I've managed to take two different issues and conglomerate them into and embarrasing mess. #!/bin/bash # Set some variables dir1=/path/that/isnt/variable/$variabledir/dir/ dir2=/path/that/isnt/variable/$variabledir/important/"$variabledir"-subdirectory/path/ echo "Gimme... (7 Replies)
Discussion started by: karlp
7 Replies

4. Shell Programming and Scripting

Bash user input

Hi all, I currently have a script which uses read -p for user interaction. e.g. read -p "New user? " user Is it possible to have it so if the user enters nothing and just presses return it can resort to a specified value instead? Thanks! :) (5 Replies)
Discussion started by: JayC89
5 Replies

5. Shell Programming and Scripting

Is there a simpler way to validate user input for float?

I'm trying to only read price (FLOAT (i.e 1.10, 3.14, etc etc)) If the input is just an integer, I will add a .00 behind. (i.e 3 becomes 3.00 , 20 becomes 20.00) If the input is without 2 decimal places, I'll add a 0. (i.e 3.1 becomes 3.10) I tried using the below code, it works but I don't... (6 Replies)
Discussion started by: andylbh
6 Replies

6. Shell Programming and Scripting

Help with Bash user input

I am starting to learn how to use bash and I would like the script to do the following: Asks the user for his/her name Asks the user for one number Asks the user for another number Then it adds the two numbers, Also multiply the two numbers I have the part where you get the name, and I... (3 Replies)
Discussion started by: boyboy1212
3 Replies

7. Shell Programming and Scripting

[bash] how is proper way to validate user input

hi all, i have a script that need user input provide all variables that needed to complete a job. this is my current script: echo "type file source and it full path :" read INPUTFILE if || ; then echo "ERROR: you didn't enter a file source or file source is not... (2 Replies)
Discussion started by: makan
2 Replies

8. Shell Programming and Scripting

Using read to prompt for editable user input in Bash 3

Below is a simple script to prompt for user input while suggesting an editable default value at the prompt: shortname=user1 read -e -i $shortname -p "Please enter the username you would like to add: " input USERNAME="${input:-$shortname}" Please enter the username you would like to add:... (3 Replies)
Discussion started by: woodson2
3 Replies

9. Shell Programming and Scripting

BASH - read does not wait for user input in some circumstances

Hello. I am running 2 scripts : script_1 and script_2 These scripts are run as root Script 2 contains : #!/bin/bash # # ~/bin/script_2 # E_BAD_PARAM=115 # date2stamp () { date --date "$1" +%Y-%m-%d___%H:%M:%S } # USER_NAME=$1 NB_PARAM=$# PARAM0=$0 (2 Replies)
Discussion started by: jcdole
2 Replies

10. Shell Programming and Scripting

How to validate user's input..?

$Input_filename=$ARGV; if (!-d $Input_filename && ! -e $Input_filename) { print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n"; exit; } 1. Input Is suppose to be something like "$ABCD/def/dsed.txt". if the input is wrong the script should throw an ERROR message.... (2 Replies)
Discussion started by: Rashid Khan
2 Replies
RULI(1) 						      General Commands Manual							   RULI(1)

NAME
srvsearch, sync_srvsearch, smtpsearch, sync_smtpsearch, httpsearch, sync_httpsearch, ruli-getaddrinfo - Sample programs for RULI Library (RFC 2782) SYNOPSIS
echo _service._protocol.nongnu.org | ruli-getaddrinfo echo _service._protocol.nongnu.org | srvsearch [ options ] echo _service._protocol.nongnu.org | sync_srvsearch [ options ] echo nongnu.org | smtpsearch [ options ] echo nongnu.org | sync_smtpsearch [ options ] echo nongnu.org | httpsearch [ options ] echo nongnu.org | sync_httpsearch [ options ] DESCRIPTION
This manual page documents briefly sample programs for the ruli(3) library. ruli is a library aimed at querying DNS SRV resource records. OPTIONS
For http searches, one can force the port number by specifying it as the first option. search Use the resolver search list defined in '/etc/resolv.conf'. need_ra Require RA (Recursion Available) bit in the name server answer. noinet Don't fetch IPv4 addresses. noinet6 Don't fetch IPv6 addresses. uri_port Assume the specified default port was forced by the user-supplied URI. nowalk Don't search addresses missing from the name server answer. nofall Don't launch fallback queries for addresses, if the SRV query fails. nosort6 Don't sort the address list to give preference to IPv6 addresses. EXAMPLES
echo _telnet._tcp.nongnu.org | ruli-getaddrinfo echo _smtp._tcp.nongnu.org | srvsearch search echo _smtp._tcp.nongnu.org | sync_srvsearch search noinet6 echo nongnu.org | smtpsearch noinet echo nongnu.org | sync_smtpsearch nowalk nofall echo nongnu.org | httpsearch noinet6 echo nongnu.org | sync_httpsearch 80 SEE ALSO
ruli(3) AUTHOR
This manual page was written by Everton da Silva Marques <evertonsm@yahoo.com.br>. October 08, 2004 RULI(1)
All times are GMT -4. The time now is 11:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy