In my Bash shell the $$ variable expands to the process ID of the shell.
So why does ps print its own name when I execute this?
$ bash -c 'ps -p $$ -o comm='
ps
When I follow it with a no-op command, ps does print the name of the shell.
$ bash -c 'ps -p $$ -o comm= && true'
bash
Versions:
- GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
- ps from procps-ng 3.3.16
psexits so it can then runtrueif needed. It wouldn't need to keep itself alive untiltrueexits, though, but Bash only optimizes the case of a single command, not any tail-end command. However, ksh93 optimizes that too, e.g.ksh -c 'ps -p $$ -o comm=; ps -p $$ -o comm='printsksh,ps