# simple if command

**URL:** <https://community.unix.com/t/simple-if-command/221078>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [November 18, 2008, 11:42am UTC](https://community.unix.com/t/simple-if-command/221078 "2008-11-18T11:42:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bn\_unx](https://community.unix.com/letter_avatar/bn_unx/32/5_5575768a8748004e209b776fc1b2916d.png) [@bn\_unx](https://community.unix.com/u/bn_unx)\
**Post date:** [November 18, 2008, 11:42am UTC](https://community.unix.com/t/simple-if-command/221078/1 "2008-11-18T11:42:08Z")

</div>

#! /bin/sh

envname=$1

if ["${envname}" =""]; then  
echo usage : `basename $0` envname  
exit -1  
fi

can someone explain what exactly this does

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [November 18, 2008, 11:59am UTC](https://community.unix.com/t/simple-if-command/221078/2 "2008-11-18T11:59:07Z")

</div>

When you invoke a script

```nohighlight
myscritpname.sh arg1 arg2

```

you can enter whatever arguments you want, whether the script likes it or not.  
This script will tell you if the number of arguments you gave it is not equal to 1  
First it sets envame = parameter #1  
Then it tests to see if the envanme variable is "empty". If the variable is empty the script print a message  
showing the correct usage of the script, then exits with error status.

FWIW the correct way to do this in modern POSIX shells is:

```nohighlight
if [-z $envname] ; then
 echo usage : `basename $0` envname
 exit -1
fi

```
