I'm not that good with bash, but I'm trying to create a script to kill some java processes:
/usr/ucb/ps -auxww \
| grep 'XUnit' \
| grep -v 'grep' \
| cut -c -2000 \
| awk '{print $2;}' \
| xargs kill
cut
is used here because awk
can fail with excessively long lines (see references to LINE_MAX
limit in the POSIX specification for awk).
The problem occurs when there are no such processes - xargs
tries to run kill
with no arguments, resulting in an error.
My xargs does not accept -r
or --no-run-if-empty
args, as suggested in answers to a related question that doesn't specify POSIX compliance.