DEV Community

Discussion on: What was your win this week?

Collapse
 
quii profile image
Chris James

Learned about bash traps.

Extremely useful for cleaning up your scripts but still want them to return whatever exit code you want.

#!/usr/bin/env bash

set -e

function finish {
  docker-compose down
}
trap finish EXIT

docker-compose down
docker-compose up --build --abort-on-container-exit --exit-code-from acceptance_test acceptance_test