The UNIX and Linux Forums  

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 Script Need Help kulbir Shell Programming and Scripting 2 02-26-2008 09:14 PM
Please Help On Simple Shell Script dmosheye Shell Programming and Scripting 1 09-18-2006 03:38 PM
need a simple shell script Mar1006 Shell Programming and Scripting 1 08-01-2006 07:45 AM
simple shell - how to get a parameter typed in a shell script cmitulescu Shell Programming and Scripting 3 12-05-2001 11:04 AM
A Simple shell Script provo Shell Programming and Scripting 2 12-04-2001 01:42 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2005
Registered User
 

Join Date: Nov 2005
Posts: 5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-06-2005
Registered User
 

Join Date: Dec 2005
Posts: 23
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
  #3 (permalink)  
Old 12-06-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,313
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash exec bash for loop close_wait command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix dead.letter find grep find null character in a unix file grep multiple lines grep or grep recursive inaddr_any inappropriate ioctl for device ksh if logrotate.conf lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi substitute vi+substitute+end+of+line+character while loop within while loop shell script


All times are GMT -7. The time now is 07:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101