Other posts here on SO about that error message are all about a missing whitespace or ; but it seems not to be the case for my code. Unfortunately I can't even tell on which line it is because Bitbucket gives me a too high line number. Shellcheck seems to pass for this code, so I am lost here.
Context: $Foo is a pipeline variable with a default, so should always have at least some value. The middle part is just joining of a shell string array: https://stackoverflow.com/a/2317171/4125622
script:
- >
declare -a appsArr
if [ $Foo == 'deploy' ]; then appsArr+=("foo"); fi
if [ ${#appsArr[@]} ]; then
AppsJoined=$(printf ", %s" "${appsArr[@]}")
AppsFinal=${AppsJoined:1}
fi
if [ -z "$AppsFinal" ]; then
echo "No apps selected, exiting..."
exit 1
fi
echo "Will build and deploy following apps:"
mkdir tmp && echo "${AppsFinal}" |& tee tmp/bar.txt