3304 (some bash-commando-argument-existance-check-note)

#pos1
if [ $1 != '' ] && [ $2 != '' ]
then 
    do something.....
----
#pos2
Try using the -z test:

if [ -z "$1" ] && [ -z "$2" ]

From man bash:

-z string
   True if the length of string is zero.
----
#pos3
$ fullvar=somestring
$ emptyvar=
$ echo "<${fullvar+set}>"
<set>
$ echo "<${emptyvar+set}>"
<set>
$ echo "<${unsetvar+set}>"
<>
----
if [ $# -eq 0 ]
  then
    echo "No arguments supplied"
fi

Leave a comment