might need to rewrite using gnu getopts instead of arg matching
[assignments.git] / assgn3 / process-pid.sh
1 #!/usr/bin/env bash
2
3 USAGE="usage: ./process-pid.sh {[-h, -a], [-f, -e] <pid>}, -s <regexp>"
4
5 # -h case
6 if [[ "$1" -eq "-h" ]]; then
7 echo "$USAGE"; exit 0
8
9 # <pid> case
10 elif [[ "$1" =~ ^-?[0-9]+$ ]]; then
11 if `ps $1 > /dev/null 2>&1`; then
12 echo "you win!"; exit 0
13
14 else
15 echo -ne "invalid pid\n$USAGE"; exit 1
16 fi
17
18 # -e <pid> case
19 elif [[ "$1" -eq "-e" && "$2" =~ ^-?[0-9]+$ ]]; then
20 if `ps $2 > /dev/null 2>&1`; then
21 echo "you win!"; exit 0;
22
23 else
24 echo -ne "invalid pid\n$USAGE"; exit 1
25
26 # -s <pid> <regex> case
27 elif [[ "$1" -eq "-s" && "$2" =~ ^-?[0-9]+$ ]]; then
28 if `ps $2 > /dev/null 2>&1`; then
29 echo "you win!"; exit 0;
30
31 else
32 echo -ne "invalid pid\n$USAGE"; exit 1
33
34 else
35 echo "$USAGE"; exit 1
36 fi