Blame Scripts/Bash/Functions/Commons/cli_parseArgumentsReDef.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# cli_parseArgumentsReDef.sh -- This function initiates/reset and
878a2b
# sanitates positional parameters passed to this function and creates
878a2b
# the the list of arguments that getopt will process.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function cli_parseArgumentsReDef {
878a2b
878a2b
    local ARG
878a2b
878a2b
    # Clean up arguments global variable.
878a2b
    ARGUMENTS=''
878a2b
878a2b
    # Fill up arguments global variable with current positional
878a2b
    # parameter  information. To avoid interpretation problems, use
878a2b
    # single quotes to enclose each argument (ARG) from command-line
878a2b
    # idividually.
878a2b
    for ARG in "$@"; do
878a2b
878a2b
        # Sanitate option arguments before process them.  Be sure that
878a2b
        # no option argument does contain any single quote (U+0027)
878a2b
        # inside; that would break option parsing.  Remember that we
878a2b
        # are using single quotes to enclose option arguments in order
878a2b
        # to let getopt to interpret option arguments with spaces
878a2b
        # inside.  To solve this issue, we replace all single quotes
878a2b
        # in the arguments list with their respective codification and
878a2b
        # reverse the process back when doPrint them out.
878a2b
        ARG=$(echo $ARG | sed "s/'/\\\0x27/g")
878a2b
878a2b
        # Concatenate arguments and encolose them to let getopt to
878a2b
        # process them when they have spaces inside.
878a2b
        ARGUMENTS="$ARGUMENTS '$ARG'"
878a2b
878a2b
    done
878a2b
878a2b
}