My shell script looks something like this...
if [[ $uptime -lt 0 ]];then some code fi if [[ $questions -lt 1 ]];then some code fi if [[ $slow -gt 10 ]];then some code fi
How do I use OR and have a single if clause?
$() – the command substitution. ${} – the parameter substitution/variable expansion.
The behavior of && in a shell script It is important to note that && is used not only for checking for tests/conditions, but also to run two or more commands. Thus, the commands after && will only run if the commands before && return as "True".
"$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...). So basically, $# is a number of arguments given when your script was executed. $* is a string containing all arguments. For example, $1 is the first argument and so on.
$? is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. That line is testing whether the grep command succeeded. The grep manpage states: The exit status is 0 if selected lines are found, and 1 if not found.
if [ $uptime -lt 0 -o $questions -lt 1 -o $slow -gt 10 ] ; then some code fi
See man test
for available syntax and options. The [
operator is just shorthand for test
, so the above code is equivalent to:
if test $uptime -lt 0 -o $questions -lt 1 -o $slow -gt 10 ; then some code fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With