projects
/
assignments.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8fbe044
)
might need to rewrite using gnu getopts instead of arg matching
author
kremlin
<ian@kremlin.cc>
Tue, 16 Sep 2014 21:26:28 +0000
(17:26 -0400)
committer
kremlin
<ian@kremlin.cc>
Tue, 16 Sep 2014 21:26:28 +0000
(17:26 -0400)
assgn3/process-pid.sh
patch
|
blob
|
blame
|
history
diff --git
a/assgn3/process-pid.sh
b/assgn3/process-pid.sh
index daa6624cfca31272c6b9f9160d132e93f86db834..38375037e84729c4fa81ee2fe432701839a12405 100755
(executable)
--- a/
assgn3/process-pid.sh
+++ b/
assgn3/process-pid.sh
@@
-2,10
+2,12
@@
USAGE="usage: ./process-pid.sh {[-h, -a], [-f, -e] <pid>}, -s <regexp>"
USAGE="usage: ./process-pid.sh {[-h, -a], [-f, -e] <pid>}, -s <regexp>"
-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 :(
+# <pid> case
+elif [[ "$1" =~ ^-?[0-9]+$ ]]; then
if `ps $1 > /dev/null 2>&1`; then
echo "you win!"; exit 0
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
echo -ne "invalid pid\n$USAGE"; exit 1
fi
-elif [[ "$1" -eq "-h" ]]; then
- echo "$USAGE"; exit 0
+# -e <pid> 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 <pid> <regex> 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
fi