X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=assignments.git;a=blobdiff_plain;f=assgn3%2Fprocess-pid.sh;h=38375037e84729c4fa81ee2fe432701839a12405;hp=0676b8b73b67cc44ade2cabcd119500641828ce0;hb=259095d53e66747299b5f734077a90de9db4373b;hpb=bfcad051de6e4355ad1011a6f589cbc9686a1cdd diff --git a/assgn3/process-pid.sh b/assgn3/process-pid.sh index 0676b8b..3837503 100755 --- a/assgn3/process-pid.sh +++ b/assgn3/process-pid.sh @@ -1,6 +1,36 @@ #!/usr/bin/env bash -if [ -z "$1" ] || [ "$1" = "-h" ] ; then - echo "usage: ./process-pid.sh [command] [pid]" - exit 1; +USAGE="usage: ./process-pid.sh {[-h, -a], [-f, -e] }, -s " + +# -h case +if [[ "$1" -eq "-h" ]]; then + echo "$USAGE"; exit 0 + +# case +elif [[ "$1" =~ ^-?[0-9]+$ ]]; then + if `ps $1 > /dev/null 2>&1`; then + echo "you win!"; exit 0 + + else + echo -ne "invalid pid\n$USAGE"; exit 1 + fi + +# -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