The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
simple shell - how to get a parameter typed in a shell script cmitulescu Shell Programming and Scripting 4 01-09-2009 08:45 PM
Simple Shell Script Need Help kulbir Shell Programming and Scripting 2 02-27-2008 01:14 AM
Please Help On Simple Shell Script dmosheye Shell Programming and Scripting 1 09-18-2006 06:38 PM
need a simple shell script Mar1006 Shell Programming and Scripting 1 08-01-2006 10:45 AM
A Simple shell Script provo Shell Programming and Scripting 2 12-04-2001 05:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-06-2005
djt0506 djt0506 is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 5
simple shell script problem

hi all. i have a little problem. im basically reading input from the user from the keyboard into the variable "phonenumber". I want to do a little error check to check if the user doesnt enter anything in for the value phonenumber.

i had this:

read phonenumber

if [ $phonenumber=" " ]
then
.....
else
.....
fi

but thatjust performs then instructions in between "then" and "else", but not "else" and "fi". any ideas?

thanks all in advance for your help.
  #2 (permalink)  
Old 12-06-2005
Bhups Bhups is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 23
solution:recursively calling a function

hiiii djt0506,

got a easy solution for you ...

you neeed to write a function "function Func_validate_phone_number" which will validate the phone number entered by the user.
if the ph no is blank it will again call the same function and will ask the user to enter it again....until he enters any thing other than "enter".

if you want to validate it further (for valid numbers or no characters etc) then you need to do some more validations....which again quiet easy .

here is my code....

function Func_validate_phone_number {

if [ -z "$ph" ]
then
echo "Phone Number cannot be blank....please re-enter."
read ph
Func_validate_phone_number "$ph"
else
echo "Thanks for giving your phone number.....bye"
fi

}


echo "Enter the phone number"
read ph
Func_validate_phone_number "$ph"



i have tested it .....it works fine ...

cya
  #3 (permalink)  
Old 12-07-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Keep the code short and simple. Bhups, you have a nice idea there, but I think it may be confusing for some (recursive code can be).
Code:
#!/usr/bin/sh
echo "Enter phone number: \c"
while read phone_no; do
        if [ -n "$phone_no" ]; then
                break
        fi
        echo "No input offered. Please enter phone number: \c"
done
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0