I need a dry run function in my bash scripts


usage () {
echo “Usage: $0 [-d -h]”
echo “-d flag to dry run – show syntax only”
echo “-h flag to show help file with examples”
exit 1

Run () {
if [[ ${dd} ]] ; then echo DRY_RUN: “$*” ; else eval “$@” ; fi

#process and check the commandline arguments
while getopts “:dh” option; do
case “${option}” in
d) dd=”Y” ;;
h) usage ;;
*) usage ;;
shift $((OPTIND-1))

Run “echo ${HOSTNAME}”

Above is what I used for a dryrun bash ability based on two dry run approaches I located for my bash scripting from the internet.

A run function in the script:

http://knowledgepile.net/?p=58 and http://serverfault.com/questions/147628/implementing-dry-run-in-bash-scripts

Setting an environment variable:


Bonus is inserting the package install into the bash script:

http://perlmaven.com/shell and http://stackoverflow.com/questions/1298066/check-if-a-package-is-installed-and-then-install-it-if-its-not


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: