Just enough bash to be dangerous

Hugo Di Francesco on July 26, 2018

A bash cheat sheet for developers who just want to get by. Writing setup, CI and deployment flows means a bit of the old bash scripting. Desp... [Read Full]

You should put spaces between the test brackets and the test conditions like [ -f foo.txt ] otherwise you'll get a command not found error.

The environment variable one is over-complicated - you don't need the else, and you don't need to use false to ensure that the last command is run if you use a semicolon:

# long
if [[ -z "${CIRCLE_BRANCH}"] ]; then
    npm run redis-cli flushall

npm run sync

# one-liner
[-z "${CIRCLE_BRANCH}"] && npm run redis-cli flushall; npm run sync

Good stuff! I feel like I know how to get around Bash, but I keep learning new tricks ever day, and I learned a few here, thanks!

Also, seeing that you have to end case block with the reverse esac just makes me giggle!


I don't like ask the user. The best answer is the one I will not ask.


BASH Docs are your best friend; especially peeping others legit scripts too of course.

Thanks for this insight too!

code of conduct - report abuse