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
Post a Comment