Last active
August 29, 2015 14:19
-
-
Save bcalmac/5c6a265707e26be46cd7 to your computer and use it in GitHub Desktop.
Bash utility function to run a command in a given directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Runs a command in a given directory and preserves the $? of the command | |
# Example: "runin /src/project mvn install" | |
function runin { | |
pushd $1 | |
shift | |
"$@" | |
local STATUS=$? | |
popd | |
return $STATUS | |
} | |
runin . ls runin.sh || echo "Unexpected failure" | |
runin . ls missing.sh && echo "Unexpected success" | |
function return-test { | |
runin . ls missing.sh && return | |
} | |
return-test && echo "Unexpected success" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment