#bashscripting nugget:

When testing for a value (in this case, whether an argument was attached to a call for a script) one *could* use an if/then/else statement.

Or, one can be creative with logical operators:

[[ $1 ]] && varInstance=$1 || read -p “`echo -e ‘\nNothing Entered!\nPlease Enter an Instance: ‘`” varInstance 

When using compound logical operators, they are evaluated in order of precedence. In this particular case, from left to right. So, we evaluate whether $1 and whether setting varInstance equal to $1 are true, if either returns false, we resort to the ‘or’ and read the input.

We could, for the sake of clarity (or if combining many operators) have grouped our first compound logical test like this (which is the *better* practice): 

{ [[ $1 ]] && varInstance=$1; } || { our next statement; } 

For more on logical operators and precedence, see: https://lnkd.in/gvAM5sH

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>