$ shellcheck myscript
[Line 2:](javascript:setPosition(2, 1))
PID="$(ps -o pid,args -ww -p $(pgrep java) | grep com.ibm.is.log4j.SpaceChecker | grep normalcycle)"
^-- [SC2034](https://www.shellcheck.net/wiki/SC2034) (warning): PID appears unused. Verify use (or export if used externally).
^-- [SC2009](https://www.shellcheck.net/wiki/SC2009) (info): Consider using pgrep instead of grepping ps output.
^-- [SC2046](https://www.shellcheck.net/wiki/SC2046) (warning): Quote this to prevent word splitting.
Here's what I wanted or expected to see:
SC2009 is not really an issue: the $(pgrep java) list the pids I want, making the main concern of SC2009 (to get the wrong process type) to be no longer an issue. In this example, I want to look for java processes that run a specific class and have a specific parameter.
changed the title
False positive for SC2009 : should cope the use of pgrep for collecting pids and then grepping process details
False positive for SC2009 : should cope with the use of pgrep for collecting pids and then grepping process details
Sep 28, 2022
Well, if we want to discuss the operating system commands ... ideally we should have advanced queries inside a single command: what I want is something like "select processes.pid, processes.args where args[0] like '%/java' and args[x] like '%SpaceChecker%' and args[y] like 'normalcycle' and y > x". :) .