Hour 15

1: Given the following shell function
lspids() { /bin/ps -ef | grep "$1"| grep -v grep ; }

make the necessary changes so that when the function is executed as follows

$ lspid -h ssh

the output looks like this:

UID   PID  PPID  C    STIME TTY       TIME COMMAND
root  2121     1  0  Nov 16  ?         0:14 /opt/bin/sshd

Also, when the function executes as

$ lspid ssh

the output looks like this:

root  2121     1  0  Nov 16  ?         0:14 /opt/bin/sshd

Here you are using ssh as the word specified to grep, but your function should be able to use any word as an argument.

Also, validate that you have enough arguments before executing the ps command.

If you are using a Linux or BSD-based system, please use the following version of the function lspids as a starting point instead of the version ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.