Skip to main content
Rollback to Revision 2
Source Link
user79743
user79743

Just re-usinguse the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

Just re-using the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

Just re-use the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

added 2 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 421

Just re-useusing the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

Just re-use the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

Just re-using the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

added 2 characters in body
Source Link
user79743
user79743

Just re-use the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s''%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

Just re-use the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

Just re-use the first variable:

psaux="$( ps aux | grep "someProcessName" )"
pscount="$( printf '%s\n' "$psaux" | wc -l )"

The command grep is called only once.
The result of such call is re-used to count lines.

Source Link
user79743
user79743
Loading