Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@BenGardiner
Created January 30, 2012 04:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenGardiner/1702594 to your computer and use it in GitHub Desktop.
Save BenGardiner/1702594 to your computer and use it in GitHub Desktop.
An example of how to do 'verbose' mode and a dry-run mode together
#!/bin/bash
function echo_and_exec()
{
echo "Executing $@" ; "$@"
}
function set_exec()
{
if [ -z "${DRYRUN}" ]; then
DRYRUN="false"
fi
if [ -z "${VERBOSE}" ]; then
VERBOSE="false"
fi
if ${DRYRUN}; then
EXEC="echo Not Executing "
elif ${VERBOSE}; then
EXEC="echo_and_exec"
else
EXEC=""
fi
}
VERBOSE=true set_exec
${EXEC} ls
DRYRUN=true set_exec
${EXEC} ls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment