The BASH scripting language provides a very handy 'loop' features. we have discussed that we can chain certain commands such as:
strace -p `pgrep -u root sshd`
This command however, provided that pgrep returns more than 1 process, will result in an error, since strace does not expect more than 1 process at a time. To overcome this issue, we can edit the line and add a loop control structure:
for i in `pgrep -u root sshd`; do strace -p $i ; done
What the above line will do is to create a for loop and for each result of pgrep to run strace -p.
Learn what advanced bash loops tutorial involves and how to apply the steps in this guide.
Was this article helpful?
Still need help?
Our support team can walk you through setup, troubleshooting, and account questions.
