Last active
August 29, 2015 14:05
-
-
Save adamcstephens/3dad4347ad278c1ed653 to your computer and use it in GitHub Desktop.
bash_verbose_options
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
#!/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