From: kremlin Date: Mon, 15 Sep 2014 23:52:48 +0000 (-0400) Subject: needs a gross regex for param + numerical checking X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?a=commitdiff_plain;h=8fbe044c93bcfd49863ce8c7c472d083753f19ff;p=assignments.git needs a gross regex for param + numerical checking --- diff --git a/assgn3/process-pid.sh b/assgn3/process-pid.sh index 0676b8b..daa6624 100755 --- a/assgn3/process-pid.sh +++ b/assgn3/process-pid.sh @@ -1,6 +1,18 @@ #!/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 " + +if [ -z "$1" ]; then + echo "$USAGE"; exit 1 + +elif [[ "$1" =~ ^-?[0-9]+$ ]]; then # unportable :( + if `ps $1 > /dev/null 2>&1`; then + echo "you win!"; exit 0 + + else + echo -ne "invalid pid\n$USAGE"; exit 1 + fi + +elif [[ "$1" -eq "-h" ]]; then + echo "$USAGE"; exit 0 fi