DEV Community

Discussion on: Just enough bash to be dangerous

moopet profile image
Ben Sinclair

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
hugo__df profile image
Hugo Di Francesco Author • Edited

Thanks I've updated it.