[kwlug-disc] Question about `ps` and `grep`
Chris Craig
kwlug.org at ciotog.net
Wed Sep 25 21:19:33 EDT 2024
It's simply that the string "[t]mux" doesn't match the regex "[t]mux"
On Wed, Sep 25, 2024 at 9:07 PM Ronald Barnes via kwlug-disc <
kwlug-disc at kwlug.org> wrote:
>
> I watched a recent video about bash on YouTube channel "You Suck At
> Programming" and a comment there has me completely baffled.
>
>
> The topic was `pgrep` and `pkill` instead of `ps aux | grep ...`.
>
>
> The comment had a solution to seeing the `grep` command in the output
> when grep'ing `ps` output:
>
> This shows the grep command in the output:
>
>
> # ps aux | grep tmux
> root 9032 0.0 0.0 23476 5632 pts/1 S+ Sep05 0:04 sudo
> tmux new -s w00
> root 9041 0.0 0.0 23476 1560 pts/9 Ss Sep05 0:00 sudo
> tmux new -s w00
> root 9042 0.0 0.0 10916 3712 pts/9 S+ Sep05 0:00 tmux
> new -s w00
> root 9045 0.0 0.0 14236 4920 ? Ss Sep05 1:14 tmux
> new -s w00
> root 748047 0.0 0.0 9212 2560 pts/10 S+ 17:59 0:00 grep
> --color=auto --directories=skip tmux
>
>
>
> BUT, changing what's being grep'd for by making it [t]mux:
>
> # ps aux | grep [t]mux
> root 9032 0.0 0.0 23476 5632 pts/1 S+ Sep05 0:04 sudo
> tmux new -s w00
> root 9041 0.0 0.0 23476 1560 pts/9 Ss Sep05 0:00 sudo
> tmux new -s w00
> root 9042 0.0 0.0 10916 3712 pts/9 S+ Sep05 0:00 tmux
> new -s w00
> root 9045 0.0 0.0 14236 4920 ? Ss Sep05 1:14 tmux
> new -s w00
>
>
> Now grep's output is NOT shown.
>
>
> And I cannot figure out why not?!?
>
>
> I understand that [t] is a character range (of one character), but
> without explicit anchoring, why does that work?
>
>
>
> Anyone able to explain this?
>
>
> (Also, https://www.youtube.com/@yousuckatprogramming channel is highly
> recommended - 3 to 4 minute videos, usually about `bash` topics, where
> there's always something I learn.
>
> Then check the comments for user "extrageneity", who expands on the
> topic with a Uni CS level comment.)
>
>
> Thanks,
>
> rb
>
> _______________________________________________
> kwlug-disc mailing list
> To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
> with the subject "unsubscribe", or email
> kwlug-disc-owner at kwlug.org to contact a human being.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20240925/ceb6edaa/attachment.htm>
More information about the kwlug-disc
mailing list