I'm having a problem with declaring array from STDOUT in Buildspec, which is part of Codebuild in AWS.
Buildspec using Pure Bourne Shell, so I can't use this line in code declare -a available_envs=($(eb list --all)) or available_envs=($(eb list --all))
some build command...
eb list --all # list all created env in Elastic Beanstalk
declare -a available_envs=($(eb list --all)) # <<< here is a problem because I can't create array this way.
echo ${available_envs[@]} # <<< checking if variabla have all available env
if [[ ${available_envs[*]} =~ 'develop' ]]; then
echo 'Develop environment is allready created.'
else
echo "Creating Develop environment..."
eb create develop
fi
some build command...
Thank you in advance.
Edit:
Output of command eb list --all
develop
production
stage
Solution: Thx @faho for change of view.
I trim output a little before grep command
some build command...
envs=$(eb list --all | tr -d " \t\r" | tr -d [*] | grep "develop")
echo ${envs}
if [ "${envs}" = "develop" ]; then
echo 'Develop environment is already created.'
else
echo "Creating Develop environment..."
fi
some build command...
eb list --allcommand produces. You can edit the output to disguise sensitive information.shdoesn't have arrays so you'll need to find some other way of representing the data. In finding a solution, questions that would arise will include "can the data items contain spaces or other non-printing characters?"shcan't create arrays this way, but I'm missing the solution for quite a few day now. That is why I post this question.