A typical prompt in bash in something like:
PS1="\u@\h:\w\$ "
The you can show the number of background jobs using \j, e.g.:
PS1="\u@\h:\w [\j]\$ "
Which is useful, because every now and then I forget I have a stopped job and only notice when it complains if I manually logout from the shell.
However, 95% of the time, the background job count is 0 and showing it in the prompt is superfluous.
How can I show the job count in the prompt, but only if it’s nonzero?
You can e.g. do something like this: