On Mon, Jun 26, 2000 at 04:13:18PM -0500, [EMAIL PROTECTED] wrote:
> the script is a shell script (#!/bin/sh) which I want to invoke as follows:
> 
> appinstall -s <src path> [-t <trg path>] [-softlinks]

This violates POSIX and GNU standards.  You want to replace -softlinks
with either a proper short-form option (say "-L") or a proper long-form
option (say "--softlinks").

> my problem is figuring out how to tell from a shell script if the user
> specified -s, -t, and -softlinks, and how to retrieve their associated
> values. I think awk or sed, or both, help me achieve this, but I have never
> used either one.

Wrong tool.  The right tool is "getopt"

I'll include a sample script that shows how this could be done.

--- snip snip ----------------------------------------------------------------
#!/bin/sh

USAGE="usage: $0 -s <src path> [-t <trg path>] [-L]"

if set -- `getopt 's:t:L' $@` ; then
        : getopt worked
else
        echo $USAGE >&2
        exit 1
fi
src_path=
trg_path=
softlinks=0
while : ; do
        case "$1" in
        -s)     src_path="$2" ; shift 2 ;;
        -t)     trg_path="$2" ; shift 2 ;;
        -L)     softlinks=1 ; shift ;;
        --)     shift ; break ;;
        *)      echo $USAGE >&2 ; exit 1 ;;
        esac
done
if [ $# -ne 0 ] ; then
        echo "$0: unknown parameter \"$1\"" >&2
        echo $USAGE >&2
        exit 1
fi
if [ "X$src_path" = "X" ] ; then
        echo "$0: source path not specified" >&2
        echo $USAGE >&2
        exit 1
fi

echo "src_path=$src_path"
echo "trg_path=$trg_path"
echo "softlinks=$softlinks"
--- snip snip ----------------------------------------------------------------

-- 
Chip Rosenthal <[EMAIL PROTECTED]>                      http://www.unicom.com/
Protect your mail server against spam.                http://mail-abuse.org/
Junk email is theft.  There ought to be a law.        http://www.cauce.org/
Preserve the monopoly & protect innovation: BSoD, paper clip, email worms, ...
---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]

Reply via email to