添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account False positive for SC2009 : should cope with the use of pgrep for collecting pids and then grepping process details #2597 False positive for SC2009 : should cope with the use of pgrep for collecting pids and then grepping process details #2597 abpicoli1 opened this issue Sep 28, 2022 · 2 comments

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

#!/bin/bash
PID="$(ps -o pid,args -ww -p $(pgrep java) | grep com.ibm.is.log4j.SpaceChecker | grep normalcycle)"

Here's what shellcheck currently says:

www.shellcheck output collected at Sept/28/2022

$ 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". :) .