Multiple test commands and if constructs

These type of constructs enable us to execute the second command depending on the success or failure of the first command:

command1    &&    command2 
command1    ||    command2 

Let's write script In this script, we will ask the user to input two numbers. Then, the if statement will evaluate two expressions. If both are true, then the command after then will be executed; otherwise, commands after else will be called:

echo "Enter the first number" 
read val_a 
echo "Enter the Second number" 
read val_b 
if [ $val_a == 1 ] && [ $val_b == 10 ] 
  echo "testing is successful" 
  echo "testing is not successful" 

Let's test the program:

    $ chmod +x
    $ ./

The following will ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.