how to check if $1 and $2 are null?
Try using the -z test:
if [ -z "$1" ] && [ -z "$2" ]
From man bash
:
-z string
True if the length of string is zero.
Since this is tagged bash
, I recommend that one use the extended test construct ([[...]]
), and forget the quotes:
if [[ -z $1 && -z $2 ]]; then
...
Unless you are going for sh
/POSIX compatibility, there is no reason not to use [[ ]]
.
The following also works,
if [ "$1" == "" && "$2" == ""]; then
echo NULL
fi