Skip to content

Instantly share code, notes, and snippets.

@adamcstephens
Last active August 29, 2015 14:05
Show Gist options
  • Save adamcstephens/3dad4347ad278c1ed653 to your computer and use it in GitHub Desktop.
Save adamcstephens/3dad4347ad278c1ed653 to your computer and use it in GitHub Desktop.
bash_verbose_options
#!/bin/bash
REPOSYNC_LOG=/var/log/reposync.log
while getopts ":v:d" opt; do
case $opt in
v) # write to stdout instead of log
VERBOSE='yes'
;;
d)
set -x
exec 2>&1
;;
esac
done
if [[ "$VERBOSE" != 'yes' ]]
then
# blank the log file
> $REPOSYNC_LOG
# redirect all to the log
exec &>$REPOSYNC_LOG
fi
VERSION=${@:$OPTIND:1}
[ -z $VERSION ] && usage
c=()
while getopts ":bxc:" o; do
case "${o}" in
b) b=1 ;;
x) x=1 ;;
c) c+=( "${OPTARG}" ) ;;
*) echo "usage()"; exit 1 ;;
esac
done
shift $((OPTIND-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment