About
Manipulating the input command line arguments
Code Snippets
# Arguments
if [ $# -lt 2 ]; then echo "Usage: rosrun PACKAGE EXECUTABLE [ARGS]" echo " rosrun will locate PACKAGE, cd to it, and try to find" echo " an executable named EXECUTABLE in the PACKAGE tree." echo " If it finds it, it will run it with ARGS." exit 1 fi
Listing
echo $*
You can shift individual args out with shift.
Iterating Over
echo $* shift shift echo $*
And a more complicated example:
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