[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: disable IPv6 debian



On Sat, 16 Apr 2022, tomas@tuxteam.de wrote:

On Fri, Apr 15, 2022 at 09:47:11PM -0400, The Wanderer wrote:
On 2022-04-15 at 20:47, Greg Wooledge wrote:

On Sat, Apr 16, 2022 at 08:20:40AM +0800, wilson wrote:

ps -efw |grep $PS |grep -v grep

You're also going to exit your script with the exit status from that
last grep command.  That's probably not what you want.  If it's not,
then an explicit "exit 0" at the end might be a good idea.

Or, as another choice, you might want to exit with the exit status
of the *first* grep.  In that case, switching them around would be
better:

ps -efw | grep -v grep | grep "$PS"

This would probably result in undesired behavior. I recognize this
pattern [...]

If all you want to do is to find out whether a process with PID "$PS"
is running, why not

 ps --pid "$PS" > /dev/null 2>&1 && echo "yo"

or even perhaps

 kill -0 "$PS" 2>/dev/null && echo "yo"

But yes, for the general pattern you are right.

Agree totally with this.

But if you want to use grep, then you need -w at least. grep for pid 123
will also match 1123, 1234, 11234 etc.

ps -ef | grep -w '[p]s' will not match the grep command.

ps -ef | grep -w "[${PS:0:1}]${PS:1}"


Reply to: