Firewalling 90% complete & tested, questions about writing tone

Bill's LFS Login lfsbill at nospam.dot
Wed Apr 28 15:37:15 PDT 2004


On Wed, 28 Apr 2004, Dagmar d'Surreal wrote:

><snip>

> I'll also add that anyone who doesn't like two-space tabs can bite me.
> The for loops wind up getting really, really deeply nested and there's
> no way the support script will ever be formattable within 80 columns
> unless two-space tabs are used (without making it unreadable, which is
> counterproductive).
>
> Never again will I write anything like this in bash script.  Many times
> I came very close to throwing the support code out and rewriting it in
> perl (which would have taken about three hours total).  Anyone know of a
> recipe for doing getopts style parsing for bash functions?

I'm not sure if the attached is along the lines you were thinking, but
if it looks like something close in *form*, I'll be glad to help if you
like.

-- 
NOTE: I'm on a new ISP, if I'm in your address book ...
Bill Maltby
lfsbillATearthlinkDOTnet
Fix line above & use it to mail me direct.
-------------- next part --------------
#########################################################################
# GetParameters: basic acquisition of command line parameters. NOTE:
# this does *not* use the bash builtin getopts, it uses the getopt(1)
# command. More flexibility.
#########################################################################
GetParameters()
{
    local PL PG			# Parm length, parm good length
    local RC Params		# Return code lost if combined with next

    Params=$(getopt --unquoted --name $(basename $0) \
        --options bc:d:p:r:s:w \
        --longoptions \
	no-begin,control-file:,dir:,project:,run-list:,skip-thru:,no-wrap-up \
	-- $* \
    )
    RC=$?

    if [ $RC -eq 0 ] ; then	# Looks like good parameters received
	set -- $Params		# Set 'em into positional parameters
	while [ "$1" ] ; do	# Some process *two* at a time
	    case $1 in
		-- ) test -z "$HPA" -o -z "$RCF" && {
			RC=1; echo "Missing project or control-file, rc=1"
		    }
		    shift	# Last param by getopt, '--', is only 1
		    ;;
		-b | --no-begin)		# Don't run initialization
		    NoBegin=$SKIPRUN		# cmd ln skip initialization
		    shift
		    ;;
		-c | --control-file )	# Run Control File name
		    test -z "$RCF" && RCF=$2 || {
			RC=2; echo "Dupe run control file specified, rc=$RC"
		    }
		    shift 2
		    ;;
		-d | --dir )		# Project-specific scripts dir
		    test -z "$WD" && WD=$2 || {
			RC=3; echo "Dupe working directory specified, rc=$RC"
		    }
		    shift 2
		    ;;
		-p | --project )	# High-level Project Acronym
		    test -z "$HPA" && HPA=$2 || {
			RC=4; echo "Dupe project specified, rc=$RC"
		    }
		    shift 2
		    ;;
		-r | --run-list )	# Run List
		    test -z "$RL" && RL=$2 || RL="$RL,$2"
		    shift 2
		    ;;
		-s | --skip-thru )
		    if [ -z "$ST" ] ; then
			PL=$(expr $2 : '.*');PG=$(expr $2 : '[-0-9]*')
			if [ $PL -ne $PG ]; then
			    RC=5
			    echo "skip-thru has non-numerics ($2), rc=$RC"
			else
			    ST=$2
			fi
		    else
			RC=6; echo "Multiple skip-thru specified, rc=$RC"
		    fi
		    shift 2
		    ;;
		-w | --no-wrap-up)	# Don't run de-initialization
		    NoWrapUp=$SKIPRUN	# cmd ln skip de-initialization
		    shift
		    ;;
		* )			# Unknown parameter
		    RC=7; echo "Unknown parameter, <$1>, rc=$RC"
		    shift
		    ;;
	    esac
	done
    else
        RC=8; echo "Bad parameter received, rc=$RC"
    fi

    test -z "$HPA" && {
	RC=9; echo "Required project acronym (-p <XXX>) missing, rc=$RC"
    }

    test -z "$RCF" && {
	RC=10; echo "Needed control file (-c <ctl-file>) missing, rc=$RC"
    }

    test -z "$WD" && {
	RC=11; echo "Needed work directory (-d <workdir>) missing, rc=$RC"
    }

    if [ $RC -ne 0 ] ; then
	echo "usage: E10ExecRunCtl
		[ -b | --no-begin]
		{ -c[ ] | --control-file[=| }}<control file>
		{ -d[ ] | --dir[=| }}<proj work dir>
		{ -p[ ] | --project{=| }}<acronym>
		[ { -r[ ] | --run-list{=| }}<run-list> ]
		[ { -s[ ] | --skip-thru{=| }}<sequence-number> ]
		[ -w | --no-wrap-up]" >&2
    fi

    return $RC
}


More information about the hlfs-dev mailing list