needs a gross regex for param + numerical checking
authorkremlin <ian@kremlin.cc>
Mon, 15 Sep 2014 23:52:48 +0000 (19:52 -0400)
committerkremlin <ian@kremlin.cc>
Mon, 15 Sep 2014 23:52:48 +0000 (19:52 -0400)
assgn3/process-pid.sh

index 0676b8b73b67cc44ade2cabcd119500641828ce0..daa6624cfca31272c6b9f9160d132e93f86db834 100755 (executable)
@@ -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] <pid>}, -s <regexp>"
+
+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