Why does this if match although it shouldn't?

Hi everyboy,

I am a little confused and can't understand why I get a positive match in the following case.

Shell Script section

echo $SHELL
echo "Server type = ${SERV_TYPE}"
if [[ "${SERV_TYPE}" == ["sapapp+oradb" || "sapapp"] ]]; then
    echo "foor"
    echo -e $(_date) "${cinfo}INFO: ${crst}Checking SAP memory on ${HOST}"

This is the output

/bin/bash
Server type = hanadb
foor
2018-02-23 12:21:41 INFO: Checking SAP memory on test0815

My need is that the if statement checks variable SERV_TYPE and exactly matches "sapapp+oradb" or "sapapp". So that in my example this should not match, but somehow it does :confused:

Could anyone please help me to understand what is going on here and what I have done wrong?

Kind Regards,
h1kelds

Methinks you want to use

if [[ "${SERV_TYPE}" == "sapapp+oradb" || "${SERV_TYPE}" == "sapapp" ]]; then
1 Like