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
using awk != parameter karthikn7974 Shell Programming and Scripting 4 04-28-2008 03:59 AM
checking parameter values passed to script ammu UNIX for Dummies Questions & Answers 2 10-05-2007 09:35 AM
how do I make dynamic parameter names? Or get the value of a parameter evaluated twi Awanka Shell Programming and Scripting 2 04-19-2007 06:37 PM
parameter u263066 Shell Programming and Scripting 5 10-12-2006 12:46 AM
$- parameter ... moxxx68 UNIX for Dummies Questions & Answers 2 02-10-2005 03:23 PM

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

Join Date: Jul 2006
Posts: 55
Parameter Checking

Hi all,

My script has 2 mandatory and 1 optional paramter. If the third parameter(optional) one is null the it should take a default value say 3. Can any one please write a simple code.

sh test.sh 1 2 3

var1=$1
var2=$2

if [ -z $3 ]
then
var3=3
fi

echo " the third variable $var3"

But this is erroring out saying " test.sh: test: argument expected"

Thanks in advance
Ammu
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-23-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,199
Code:
var1=$1
var2=$2

if [ -z "$3" ]
then
var3=3
fi

echo " the third variable $var3"
or
Code:
var1=$1
var2=$2
var3=${var3:-3}
echo " the third variable $var3"
Jean-Pierre.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:41 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