Blame Scripts/Functions/cli_parseArgumentsReDef.sh

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