Skip to content

Instantly share code, notes, and snippets.

@im6e
Created May 12, 2014 14:15
Show Gist options
  • Save im6e/b592030c29f100b564f5 to your computer and use it in GitHub Desktop.
Save im6e/b592030c29f100b564f5 to your computer and use it in GitHub Desktop.
dry-run function
#!/bin/bash
while getopts d OPT
do
case $OPT in
"d" ) DRY="y"; echo "[DRY RUN MODE]" ;;
esac
done
function execute() {
echo "COMMAND: ${@}"
if [[ $DRY == "y" ]]; then
return 0
fi
eval "$@"
}
execute "ls -la"
execute "pwd"
execute "echo \'Hello, world.\'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment