Stripping arguments from a bash script
I've always avoided bash-isms like arrays or slices, but I found this non-portable script interesting. I needed to strip a option and it's value because the caller couldn't be modified.
#!/bin/bash
# This script filters out "-expire X" from gskcmd and passes it down
# to "gskcmd.real"
# Get absolute install root the hokey portable way
dir=`dirname $0`
CUR_DIR=`pwd`
IHS_DIR=`dirname ${0}`
cd ${IHS_DIR}
SR=`pwd`
cd ${CUR_DIR}
if echo "$@" | grep -- -expire > /dev/null; then
COUNTER=1
while [ $COUNTER -lt $# ]; do
eval VAL=\$$COUNTER
if [ "$VAL" = "-expire" ]; then
set -- "${@:1:COUNTER-1}" "${@:COUNTER+2}"
break
fi
let COUNTER=COUNTER+1
done
fi
exec $IHS_DIR/gskcmd.real "$@"
Comments
Post a Comment