daa6624cfca31272c6b9f9160d132e93f86db834
[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 if [ -z "$1" ]; then
6 echo "$USAGE"; exit 1
7
8 elif [[ "$1" =~ ^-?[0-9]+$ ]]; then # unportable :(
9 if `ps $1 > /dev/null 2>&1`; then
10 echo "you win!"; exit 0
11
12 else
13 echo -ne "invalid pid\n$USAGE"; exit 1
14 fi
15
16 elif [[ "$1" -eq "-h" ]]; then
17 echo "$USAGE"; exit 0
18 fi