Created
November 26, 2013 04:12
-
-
Save olegchir/7653351 to your computer and use it in GitHub Desktop.
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 | |
#Argument parsing | |
#Cross-platform: GNU getopt (Linux, Macports), MacOSX getopt | |
#http://stackoverflow.com/questions/2721946/cross-platform-getopt-for-a-shell-script | |
PROG=`basename $0` | |
getopt -T > /dev/null | |
if [ $? -eq 4 ]; then | |
# GNU enhanced getopt is available | |
ARGS=`getopt --name "$PROG" --long help,locale:,python:,fsroot: --options hl:p:r: -- "$@"` | |
else | |
# Original getopt is available (no long option names, no whitespace, no sorting) | |
ARGS=`getopt hl:p:r: "$@"` | |
fi | |
if [ $? -ne 0 ]; then | |
echo "$PROG: usage error (use -h for help)" >&2 | |
exit 2 | |
fi | |
eval set -- $ARGS | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-h | --help) DISPLAY_HELP=true;; | |
-l | --locale) NOVO_LOCALE="$2"; shift;; | |
-p | --python) NOVO_PYTHON="$2"; shift;; | |
-r | --fsroot) NOVO_FS_ROOT="$2"; shift;; | |
--) shift; break;; # end of options | |
esac | |
shift | |
done | |
if [ $# -gt 0 ]; then | |
# Remaining parameters can be processed | |
for ARG in "$@"; do | |
echo "$PROG: argument: $ARG" | |
done | |
fi | |
if ${DISPLAY_HELP} ; then | |
echo "Usage:" | |
echo "-l or --locale for locale (eg -l RU or --locale=RU)" | |
echo "-p or --python for python binary full path (eg -p /opt/local/bin/python3.4)" | |
echo "-r or --fsroot for filesystem root (eg -r /git)" | |
exit ${EXIT_CODE_OK}; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment