Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@darrenrahnemoon You should quote all your variables:
mkdir -p "$ARTIFACT_DIR"
Also give yourself an explicit delete:
rm -rf "$ARTIFACT_DIR/*"
I'd also suggest using a `set -e` -
iiii90853yWhy does it even require a "force" flag at all?
That script was made by a stupid dingus -
Quoting doesn't solve the problem at hand...
Check that artifact_dir is a non empty variable would be the best.
If [[ -z "${var}" ]]; then
printf "Variable is empty\n" >&2
exit 1
fi
Don't assume defaults, don't use misleading short argument syntax.
rm --preserve-root --recursive --force "${var}/*"
Will fail if rm is so old that preserve-root isn't existant or default... Much safer.
Last but not least.
Bash option erronexit / pipefail have _a_ lot of corner cases.
Check return codes explicitly, don't rely on the behaviour of bash options.
if ! rm ...; then
printf "rm failed\n" >&2
exit 1
fi
Isn't superfluous, rather the right way to handle things cause you then have a clear and safe exit handling.
Don't rely on bash options. They have a lot of nitpicky fuckity hidden, some stuff even version dependent. It's not fun to debug :) -
Wolle9153y@aaronswartz it is a bash/shell script to deploy some code in a CI/CD pipeline. Yes it is basically executing terminal commands.
Related Rants
Things like this make me nervous ...
rant