[Putting under Plasma because I can’t see a suitable subject, and I use Plasma <grin>]
Trying to get the PID of systemsettings, I forgot to use the backticks, so just typed:
pid=pgrep systemsettings
Weird effect: this raised the systemsettings window and gave it focus.
Playing around, it’s the same whatever program I choose and I get the same behaviour with zsh, ksh and bash. It’s also the same whether I type it in konsole or xterm.
In a way, this is actually quite useful, but I wonder if anyone can explain why this is happening (and whether or not it’s a designed-in feature of pgrep).
It has nothing to do with pgrep, but rather with a bug in the biological unit between the keyboard and the chair.
Just look at your command. The first section of your command is where you are assigning the value “pgrep” to a variable called pid, and then you are using that in the second part of your command as an environment variable for invoking systemsettings. Given that the system knows that systemsettings is already running, it brings the already running instance to the foreground instead of starting a new instance.
The syntax is either
Var=command... (this was supposed to be in backticks but the forum converts them)
Or
Var=$(command…)
The latter is the more modern variant, but tick are not deprecated.