The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 05-23-2007
ammu ammu is offline
Registered User
 

Join Date: Jul 2006
Posts: 62
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
Remove advertisements
!!
Forum Sponsor