# Parameter Checking

**URL:** <https://community.unix.com/t/parameter-checking/171465>\
**Category:** Shell Programming and Scripting\
**Created:** [May 23, 2007, 1:18pm UTC](https://community.unix.com/t/parameter-checking/171465 "2007-05-23T13:18:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ammu](https://community.unix.com/letter_avatar/ammu/32/6_22734026db12803ebb3e059622ac3534.png) [@ammu](https://community.unix.com/u/ammu)\
**Post date:** [May 23, 2007, 1:18pm UTC](https://community.unix.com/t/parameter-checking/171465/1 "2007-05-23T13:18:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aigles](https://community.unix.com/user_avatar/community.unix.com/aigles/32/118_2.png) [@aigles](https://community.unix.com/u/aigles)\
**Post date:** [May 23, 2007, 1:24pm UTC](https://community.unix.com/t/parameter-checking/171465/2 "2007-05-23T13:24:00Z")

</div>

```nohighlight
var1=$1
var2=$2

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

echo " the third variable $var3"

```

or

```nohighlight
var1=$1
var2=$2
var3=${var3:-3}
echo " the third variable $var3"

```

Jean-Pierre.
