string - Checking if a variable is empty on bash in If loop -


i wanted check if value of variable empty in if statement , take action based on result same in bash script.

i doing this:

if [ -z "${originslotname-}" ] && [ -z "${targetslotname-}" ];      echo "value of both slot not given"; 

although pass argument originslotname , targetslotname empty, particular iteration not executed rather goes part of bash script expecting both originslotname , targetslotname.

does know, might wrong here? or there better way structure script? of have if statement 4 branches. if statement looks following:

if (originslotname & originslotname != empty)      else if (originslotname = empty & originslotname != empty )      else if (originslotname != empty & originslotname = empty )     else     (both originslotname & originslotname = empty ) 

is there better , more efficient way perform these checks , take relevant action based on result, apart using if?

you can write condition :

if [[ -z "${originslotname}" &&  -z "${targetslotname}" ]];     echo "value of both slot not given"; fi 

it validate condition if both $originslotname , $targetslotname empty


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -