From 259095d53e66747299b5f734077a90de9db4373b Mon Sep 17 00:00:00 2001 From: kremlin Date: Tue, 16 Sep 2014 17:26:28 -0400 Subject: [PATCH] might need to rewrite using gnu getopts instead of arg matching --- assgn3/process-pid.sh | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) 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 -- 2.41.0