I am using bash. I have a file named a2draw that contains only 1 line:sleep 99999I start it using this command:bash a2draw &Now, I know and understand the trick with square bracket that allows you to omit grep process in ps output:ps aux | grep cronroot      1079  0.0  0.0   2596   788 ?        Ss   Mar25   0:00 cronroot      1119  0.0  0.0   3684   696 ?        Ss   Mar25   0:00 /usr/sbin/incrond -f /etc/incron.confja       29781  0.0  0.0   4368   820 pts/10   S+   12:49   0:00 grep cronps aux | grep [c]ronroot      1079  0.0  0.0   2596   788 ?        Ss   Mar25   0:00 cronroot      1119  0.0  0.0   3684   696 ?        Ss   Mar25   0:00 /usr/sbin/incrond -f /etc/incron.confBut it somehow doesn't work in the subshell that has jobs running in the background:jobs[1]+  Running                 bash a2draw &ps aux | grep [a]2drawja       22977  0.0  0.0   5172  1080 pts/10   S    12:21   0:00 bash a2drawja       30242  0.0  0.0   4364   816 pts/10   R+   12:50   0:00 grepWhat is even more strange, dropping one letter from the process name yields correct results:ps aux | grep [a]2draja       22977  0.0  0.0   5172  1080 pts/10   S    12:21   0:00 bash a2drawOn another shell everything works as I expected:ps aux | grep [a]2drawja       22977  0.0  0.0   5172  1080 pts/10   S    12:21   0:00 bash a2drawps aux | grep [a]2draja       22977  0.0  0.0   5172  1080 pts/10   S    12:21   0:00 bash a2drawI don't know what's going on. Is there something special about background jobs that modify how creation of pipe works?
ps | grep shows bad output in subshell with jobs running in the background
bash;grep;pipe;ps
Had you used zsh or (t)csh instead of bash, you'd have understood your mistake:$ ps -ef | grep [c]ronzsh: no matches found: [c]ronAbove, you've got a globbing pattern that is meant to expand to the list of files in the current directory matching that pattern.In most Bourne-like and rc-like shells however, if there's no matching file, the pattern is silently passed untouched to the command.That is why it works with [c]ron, because there's no file called cron in the current directory, but not with [a]2draw, because there is one file matching that pattern in the current directory, it is expanded by the shell to a2draw and grep gets a a2draw argument instead of [a]2draw.Note that bash can be configured to work like zsh in this case by doing:shopt -s failglobThe fish shell also reports an error when a glob does not match. However [...] is not a globbing operator in fish.What that means is that you need to quote globbing characters when you don't intend them to be expanded:ps -ef | grep '[a]2draw'You can get away without doing that in bash or other Bourne-like shells except zsh, but that makes for dormant bugs ready to kick in the day you run the command in a directory that has a matching file.I can have nasty side effects like in unsuspected contexts. Like:rm -?In a directory that has files called --, -x and -y would remove both -x and -y.