...
Code Block |
---|
language | bash |
---|
title | Iterating Over |
---|
|
echo $*
shift
shift
echo $* |
And a more complicated example:
Code Block |
---|
language | bash |
---|
title | Iterating Over |
---|
|
###########################
# Macros
###########################
show_help ()
{
echo " Usage:"
echo " foo <required-options> <options>"
echo ""
echo " Required Option (one of):"
echo " --stable : work with the stable sources/binaries"
echo " --devel : work with the devel sources/binaries"
echo ""
echo " Options:"
echo " --help : show this help message"
echo " --jobs=<n> : parallelise downloads (default is 5)"
echo " -d, --source-directory=<directory> : specify custom source directory"
echo ""
exit 0
}
###########################
# PreConfigured Defaults
###########################
JOBS=5
###########################
# Command Line Parsing
###########################
for i in "$@"
do
case $i in
--help)
SHOW_HELP=1
shift
;;
--stable)
STABLE=1
shift
;;
--devel)
DEVEL=1
shift
;;
-j=*|--jobs=*)
JOBS="${i#*=}"
shift
;;
-d=*|--source-directory=*)
USE_CUSTOM_SOURCE_DIRECTORY=1
CUSTOM_SOURCE_DIRECTORY="${i#*=}"
shift
;;
*)
# unknown option
;;
esac
done
if [ ! -z "$SHOW_HELP" ]; then
show_help
exit 0
fi
if [ ! -z "$USE_CUSTOM_SOURCE_DIRECTORY" ]; then
GROOT=$CUSTOM_SOURCE_DIRECTORY
else
GROOT=/opt/groot
fi |