Home > Net >  shell script if condition giving error message in openshift platform . if[ == ] : not found [No such
shell script if condition giving error message in openshift platform . if[ == ] : not found [No such

Time:03-11

I've implemented script like below.

podName=someValue ; // Here value is dynamic (empty or non empty)

if[ $podName == " "] then

echo "Empty"

Even though I got empty an output but still could see if[ == ] : not found [No such file or directory ] error message while running the script

CodePudding user response:

Seems like there is a small formatting issue which is causing this error. This should be the correct code.

podName=someValue

if [ "$podName" == " " ]; then
    echo "Empty"
fi

CodePudding user response:

You can check if the string is empty in bash / sh like this (some containers don't have bash shell):

podName="someValue"

if [ -z "$podName" ]; then
  echo "Empty"
fi

or:

podName="someValue"

if [ "$podName" = "" ]; then
  echo "Empty"
fi

The following syntax works only in bash [ "$podName" == "" ]

  • Related