In this article, we will see how to user AND operators in bash shell script.
To recall parameters, "$1" was checking first argument, and following each n+1 with "$" sign at beginning returns corresponding parameter within script. To check total parameter count which has been passed to script, we had used "$#" variable. Lets check our parameters with AND operator to execute a code block with IF statement.
In bash shell, "-a" operator is used for AND operation.
Lets look to its syntax.
if [ $1 -gt 1 -a $2 = "delete" ]; then
Lets see it in bash shell scripting example.
As above output indicates, we used "-a" operator to perform AND logic operation with IF. When we send 2 parameter to script, it executes statements following the condition. Otherwise "else" block gets executed.