Reputation: 29
I am trying to write one if condition in Linux.
I have a variable : $check_mrp
. I want to check if this variable is not equal to either of the following three values : WAIT_FOR_LOG
or APPLYING_LOG
or WAIT_FOR_GAP
then echo
message : "Please start the Manged Recovery Process".
For example if variable value is equal to any of the three (WAIT_FOR_LOG
or APPLYING_LOG
or WAIT_FOR_GAP
) then it should not echo the message since services are running.
Upvotes: 0
Views: 460
Reputation: 289495
Use a regular expression as described in check if string match a regex in BASH Shell script:
[[ $name =~ ^(WAIT_FOR_LOG|APPLYING_LOG|WAIT_FOR_GAP)$ ]]
Note the ^
and $
to indicate that it must be exactly this string.
$ name="bla"
$ [[ $name =~ ^(WAIT_FOR_LOG|APPLYING_LOG|WAIT_FOR_GAP)$ ]] && echo "yes"
$ name="WAIT_FOR_LOG"
$ [[ $name =~ ^(WAIT_FOR_LOG|APPLYING_LOG|WAIT_FOR_GAP)$ ]] && echo "yes"
yes
Upvotes: 2
Reputation: 5875
if [[ ! $check_mrp =~ "WAIT_FOR_LOG|APPLYING_LOG|WAIT_FOR_GAP" ]]; then echo "Please start the Manged Recovery Process"; fi
Upvotes: 1
Reputation: 1242
if [ x$check_mrp == x"WAIT_FOR_LOG" ] || [ x$check_mrp == x"APPLYING_LOG" ] || [ x$check_mrp == x"WAIT_FOR_GAP" ]
then
exit 0
fi
echo "Please start the Manged Recovery Process"
exit 1
Upvotes: 0