blob: e9a91ac7942133d3a5fdaabed5eec06c22241a74 [file] [log] [blame]
#!/bin/bash
########################################################################
#- PROGRAM NAME: namevalue
#- AUTHOR & DT : David McMahon
#- RCS Ident :
#+ USAGE : . namevalue
#+ DESCRIPTION : Set local shell environment from arguments name=value
#+ or -name=value or --name=value
########################################################################
# XXX: At some point, this should find all --whatever args without an =
# and set then to true, but this will mess with all existing independent
# handling of --whatever args passed through current with LOOSEARGS.
# but a nice exercise to simplify and centralize cmd-line processing.
ORIG_CMDLINE="$*"
for arg in "$@"
do
case $arg in
*=*) # Strip off any leading -*
arg=$(echo $arg |sed 's,^-*,,g')
# "set" any arguments that have = in them
NAMEX=${arg%%=*}
# change -'s to _ for legal vars in bash
NAMEX=${NAMEX/-/_}
VALUEX=${arg#*=}
eval export $NAMEX=\""$VALUEX"\"
;;
*) LOOSEARGS="$LOOSEARGS $arg"
;;
esac
done