The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to set the File Paths for Inputs and Outputs Amruta Pitkar UNIX for Dummies Questions & Answers 1 10-31-2006 01:19 PM
Checking the format of inputs in a file sendhilmani123 Shell Programming and Scripting 13 05-19-2006 03:12 PM
redirecting serial inputs to a file? guilartec Shell Programming and Scripting 4 02-27-2006 07:30 PM
Inputs from a file sendhil Shell Programming and Scripting 4 02-01-2006 01:48 AM
Reading in two inputs from a file MadHatter Shell Programming and Scripting 1 06-29-2005 07:17 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-10-2006
Registered User
 

Join Date: Apr 2006
Posts: 33
Validating inputs from a file

Hi,

I have a file called inputs. Now that file has the values like this:
1 2 3

Now In my script called 'get.sh' I do this :
exec < inputs
read a b c d

Now I know that there will not be any value in d. How can I check it. I need the exact condition for checking whether the variable has any value or not.


Thanks in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-10-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
man test. Look for -z.

Code:
#! /bin/ksh

echo "ab bc cd" | while read a b c d
do
[ -z "$a" ] && echo "empty a" || echo "$a"
[ -z "$b" ] && echo "empty b" || echo "$b"
[ -z "$c" ] && echo "empty c" || echo "$c"
[ -z "$d" ] && echo "empty d" || echo "$d"
done
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:24 PM.


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