# Implement a bash script that receives two parameters as command line arguments. # The last parameter is a string containing the name of a command. # The script must produce the list of all the running processes launched with a command containing # the string passed to the script as a parameter. # The produced list must contain the same fields reported by the program ps -ef. # The first parameter (-h) is optional. If it is present, the bash script must print the header # (i.e, the first line) produced by the command ps. # Examples: # Input: ./es -h bash # UID PID PPID C STIME TTY TIME CMD user 2454 2449 0 18:05 pts/2 00:00:00 bash user 2816 2449 0 18:09 pts/4 00:00:00 bash user 2944 2449 0 18:14 pts/5 00:00:00 bash user 3249 2816 0 18:32 pts/4 00:00:00 bash # Input: ./es bash user 2454 2449 0 18:05 pts/2 00:00:00 bash user 2816 2449 0 18:09 pts/4 00:00:00 bash user 2944 2449 0 18:14 pts/5 00:00:00 bash user 3249 2816 0 18:32 pts/4 00:00:00 bash #!/bin/bash HEADER="false" PSCMD="/bin/ps -ef" # -e all the processes, -f full-format listing if [ "$1" = "-h" ] ; then HEADER=true echo "Script parameters before shift: $*" shift echo "Script parameters after shift: $*" fi if [ -z "$1" ] ; then # This condition is tree if length of $1 is 0 echo Usage: $0 [-h] process exit 1; fi if [ "$HEADER" = "true" ] ; then $PSCMD 2> /dev/null | head -n 1 fi $PSCMD 2> /dev/null | grep "$1" | grep -v grep exit 0