Multiple conditions in if statement shell script

user3604466 picture user3604466 · May 8, 2014 · Viewed 115k times · Source

I would like to know whether it is possible to have more than two statements in an if statement when you are writing a shell script?

username1="BOSS1"
username2="BOSS2"
password1="1234"
password2="4321"

if(($username == $username1)) && (($password == password1)) || 
  (($username == $username2)) && (($password == password2)) ; then

This does NOT work. But is there a way to make it work?

Thanks!

Answer

nettux picture nettux · May 8, 2014

if using /bin/sh you can use:

if [ <condition> ] && [ <condition> ]; then
    ...
fi

if using /bin/bash you can use:

if [[ <condition> && <condition> ]]; then
    ...
fi