From: kremlin Date: Tue, 16 Sep 2014 21:26:28 +0000 (-0400) Subject: might need to rewrite using gnu getopts instead of arg matching X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=assignments.git;a=commitdiff_plain;h=259095d53e66747299b5f734077a90de9db4373b might need to rewrite using gnu getopts instead of arg matching --- diff --git a/assgn3/process-pid.sh b/assgn3/process-pid.sh index daa6624..3837503 100755 --- a/assgn3/process-pid.sh +++ b/assgn3/process-pid.sh @@ -2,10 +2,12 @@ USAGE="usage: ./process-pid.sh {[-h, -a], [-f, -e] }, -s " -if [ -z "$1" ]; then - echo "$USAGE"; exit 1 +# -h case +if [[ "$1" -eq "-h" ]]; then + echo "$USAGE"; exit 0 -elif [[ "$1" =~ ^-?[0-9]+$ ]]; then # unportable :( +# case +elif [[ "$1" =~ ^-?[0-9]+$ ]]; then if `ps $1 > /dev/null 2>&1`; then echo "you win!"; exit 0 @@ -13,6 +15,22 @@ elif [[ "$1" =~ ^-?[0-9]+$ ]]; then # unportable :( echo -ne "invalid pid\n$USAGE"; exit 1 fi -elif [[ "$1" -eq "-h" ]]; then - echo "$USAGE"; exit 0 +# -e case +elif [[ "$1" -eq "-e" && "$2" =~ ^-?[0-9]+$ ]]; then + if `ps $2 > /dev/null 2>&1`; then + echo "you win!"; exit 0; + + else + echo -ne "invalid pid\n$USAGE"; exit 1 + +# -s case +elif [[ "$1" -eq "-s" && "$2" =~ ^-?[0-9]+$ ]]; then + if `ps $2 > /dev/null 2>&1`; then + echo "you win!"; exit 0; + + else + echo -ne "invalid pid\n$USAGE"; exit 1 + +else + echo "$USAGE"; exit 1 fi