I am new to bash scripting, I wish to have if condition ladder
I am reading a string, based on which I want the correct if condition to be processed.
The logic is as follows -
If the string contains a substring -deploy
, only then allow it to enter the if condition ladder.
If the string contains both -functions
and -layer
substrings, then only my 1st if condition block needs to be called,
elsif check for -functions
substring
elsif check for -layer
substring
I've come up with the following code so far-
commitMessage='[STABLE] -deploy -functions [one,two] -layer some commit message'
if [[ ($commitMessage == *"deploy"* ) && ($commitMessage == *"functions"*) || ($commitMessage == *"layer"*) ]] ; then
if [[ ($commitMessage == *"functions"*) && ($commitMessage == *"layer"*) ]] ; then
echo 'functions and layer'
fi
elsif [[ $commitMessage == *"functions"* ]] ; then
echo 'functions only'
fi
elsif [[ $commitMessage == *"layer"* ]] ; then
echo 'layer only'
fi
fi
I am getting a syntax error for elsif -
syntax error near unexpected token `elif'
I am referring this, but don't understand what I'm doing wrong -
Bash IF : multiple conditions