添加链接
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
  • Rule Id (if any, e.g. SC1000): SC2024
  • My shellcheck version ( shellcheck --version or "online"): 0.4.6
  • [?] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086 )
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit
  • Here's a snippet or screenshot that shows the problem:

    #!/bin/bash
    sudo -u apache php foo.php > /tmp/out

    Here's what shellcheck currently says:

    Line 2:
    sudo -u apache php foo.php > /tmp/out
                               ^-- SC2024: sudo doesn't affect redirects. Use ..| sudo tee file
    

    Here's what I wanted or expected to see:

    No warnings.

    My justification is that bash is a common language used in bootstrapping and provisioning, while doing these operations it's often necessary to start a script as root and ideal to run a script in another language as another user.

    In the case of web apps to avoid accidentally creating files like logs as root, but we still want to capture the output somewhere temporarily for buffering (e.g check exit status and only pass up the output of the script if it exits non-zero).

    The advice to use sudo tee file is inappropriate here (which I'll admit is mentioned on the wiki page) but it seems like this warning would almost never be relevant to anyone sudoing to a user other than root.

    Alternatively, perhaps the original check would be better to only display if the path was under /etc?