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 > Shell Programming and Scripting
.
google unix.com



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
handling maximum number characters in an input file chrysSty UNIX and Linux Applications 1 05-12-2008 10:19 AM
handling null values in files ammu Shell Programming and Scripting 1 11-06-2007 04:43 PM
Null Character Handling npk2210 Shell Programming and Scripting 3 09-29-2007 04:51 AM
compare null with non-null nitin Shell Programming and Scripting 8 11-04-2006 07:58 PM
Null handling in scripts mohanprabu Shell Programming and Scripting 3 01-20-2005 04:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-10-2006
DrRo183 DrRo183 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 10
Handling null input...

Ok, so when a user inputs nothing, simply pressing enter when prompted for a phone number, I get a "./addrbkfct.sh: test: argument expected" error message. I have the following function:

Code:
addNumber(){
        echo "Phone number: \c";
        read number;
        echo $number;
        if [ -z $number ] ; then
                echo "WARNING: no number";
                addEmail "$1" "$2" "$number";
        else
                echo $number | egrep '[+]?[-]?[0-9]?[0-9]?[0-9]?[-]?[0-9][0-9][0-9][-]?[0-9][0-9][0-9][0-9]';
                if [ $? -eq 0 ] ; then
                        addEmail "$1" "$2" "$number";
                else
                        addNumber "$1" "$2";
                fi
        fi
}
  #2 (permalink)  
Old 04-10-2006
DrRo183 DrRo183 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 10
Got it.

Code:
addNumber(){
        echo "Phone number: \c";
        read number;
        echo $number;
        if [ -z "$number" ] ; then       # <==== should be double quoted...
                echo "WARNING: no number";
                addEmail "$1" "$2" "$number";
        else
                echo $number | egrep '[+]?[-]?[0-9]?[0-9]?[0-9]?[-]?[0-9][0-9][0-9][-]?[0-9][0-9][0-9][0-9]';
                if [ $? -eq 0 ] ; then
                        addEmail "$1" "$2" "$number";
                else
                        addNumber "$1" "$2";
                fi
        fi
}
  #3 (permalink)  
Old 04-11-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Or...
Code:
if [[ -z $number ]] ; then       # <==== use double square-brackets
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 02:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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