In my script I use
winccoaID=$(ps -aux | grep -v 'color=auto' | grep -i 'WCCOAui -console' | tr -s ' ' | cut -d ' ' -f 2)
winccLogID=$(ps -aux | grep -v 'color=auto' | grep -i 'WCCOAtoolLogView' | tr -s ' ' | cut -d ' ' -f 2)
each line looks for a certain process and assigns the pid to the value.
On cli the command works as expected. BUT in the script the commands grab another random value and adds it with a space between the 2 values. I have checked the numbers against the process list. The numbers do not relate to other process. So there is no bogus grep spoiling my fun.
Can someone tell me what is going on?
grep --color=autoisn't used by the script. – muru Aug 15 '19 at 07:13pgrepand forget about thatps |grep|grep|tr|cutforever. There's no guarantee whatsoever that in a pipeline likea|b|cawill finish beforebandcare started. – Aug 15 '19 at 07:15finishes? It's usually not theps, but thegrep` that ends up as a spurious result. – ilkkachu Aug 15 '19 at 07:33grepto not appear in the output ofps -aux | grep fooit should be that either a)grephas terminated beforepshas come to read its/proc/PIDinfo or b)grepwas started afterpshas finished reading the/procdir. a) cannot be, becausegrephas to process all the output ofps. So that leaves b), and "psfinish beforegrepis started" is an acceptable approximation for it. – Aug 16 '19 at 02:35pssees itself. – ilkkachu Aug 16 '19 at 05:52