Я считаю, что функции-оболочки очень полезны для такого рода вещей:
pgrep() {
local app=${!#} pids
# now invoke the *command* pgrep and
# capture the output into an array of lines
readarray -t pids < <(command pgrep "$@")
# print the output
printf "%s\n" "${pids[@]}"
# and print the summary
printf "\nThere are currently %d processes running under the application '%s'\n" \
"${#pids[@]}" \
"$app"
}
Это также позволяет вам использовать параметры pgrep, например pgrep -fl "Google Chrome"
Проблема в том, что pgrep позволяет вам указать несколько шаблонов, и эта функция захватывает только последний как «приложение».