I built a script and when i try to run it locally it works fine, but when I run that on circleci I'm getting an error.
This is the script
#!/usr/bin/env bash
for d in */ ; do
cd $d
for f in * ; do
if [[ $f == *.sh ]]; then
if [[ $d == "test/" ]]; then
echo "$d"
else
bash *.sh
fi
else
if [[ $f == *.yaml ]]; then
echo "$file"
fi
fi
done
cd ..
done
And this is the error that I got on ci
generate-docs.sh: 4: cd: can't cd to */
generate-docs.sh: 6: [[: not found
generate-docs.sh: 15: [[: not found
CodePudding user response:
Regarding the line
bash *.sh
You seem to want to run all scripts at once. Assuming the shell files are "a.sh", "b.sh", "c.sh" etc, then the shell expands that into bash a.sh b.sh c.sh ...
meaning the first one (alphabetically) is run with all the others given as arguments. You need to loop, executing one at a time. But you're already inside a loop, so what you need there is
bash "$f"
CodePudding user response:
(I don't know circleci, but my suggestion is too lengthy to go into a comment, so I write it as answer):
First of all, I would veriry that the script runs in the correct location and using the correct shell. Therefore, I would put at the start of your script a guard like this:
#!/usr/bin/env bash
if test -z "${BASH_VERSION}"
then
echo "Needs to be executed with bash!"
exit 1
fi
echo Working Directory is "$PWD"
set -x # Only for debugging. Remove it when everything works
# ... your remaining script goes here