Skip to content

Instantly share code, notes, and snippets.

@afirth afirth/getopt.bash
Created Jul 18, 2019

Embed
What would you like to do?
bash getopt get args getargs limoncelli
#!/bin/bash
MINITEMS=1
function usage { echo " Usage: $0 [-d] [-a author] [-c file.txt] [-h] dir1 [dir1 ...] -d debug, don't actual run command -a author name of the author -c copyright override default copyright file -h this help message " exit 1 }
# Set our defaults:
DEBUG=false DEBUGCMD= AUTHOR= COPYRIGHT=copyright.txt
# Process command-line arguments, possibly overriding defaults
args='getopt da:c:h $*'
if [ $? != 0 ] then usage fi
set -- $args
for i do
case "$i" in
-h) usage shift ;;
-a) AUTHOR="$2"; shift shift ;;
-c) COPYRIGHT="$2"; shift shift ;;
-d) DEBUG=true shift ;;
--) shift; break;;
esac
done
if $DEBUG ; then
echo DEBUG MODE ENABLED. DEBUGCMD=echo
fi
# Make sure we have the minimum number of items on the command line.
if $DEBUG ;
then echo ITEM COUNT = $# ; fi
if [ $# -lt "$MINITEMS" ]; then usage fi
# If the first option is special, capture it: # THEITEM="$1" ; shift # Clone that line for each item you want to gather.
# Make sure that you adjust the MINITEMS variable to suit your needs. # If you want to do something with each remaining item, do it here
: #for i in $* ; do # echo Looky! Looky! I got $i #done
if [ ! -z "$COPYRIGHT" ]; then
if $DEBUG ; then
echo Setting copyright to: $COPYRIGHT ;
fi
CRFLAG="-copyright $COPYRIGHT"
fi LABEL='date -u +%Y%m%d'
$DEBUGCMD mkisofs -D -l -J -r -L -f -P "$AUTHOR" -V $LABEL $CRFLAG $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.