Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

SC2033 false positive #1842

Closed
zatnas opened this issue Feb 21, 2020 · 1 comment
Closed

SC2033 false positive #1842

zatnas opened this issue Feb 21, 2020 · 1 comment

Comments

@zatnas
Copy link

zatnas commented Feb 21, 2020

Intention of shell code: I'm creating a function to automatically use sudo if the command before requires user elevation. It currently works but shellcheck does not want to play nice. This might probably be similar to #1200 .

For bugs

  • Rule ID: SC2032 & SC2033
  • My shellcheck version : 0.7.0 & online
  • 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
pacman() {
	if ! command pacman "$@"; then
		echo "sudo: a password is required"
		sudo pacman "$@"
	fi
}

Here's what shellcheck currently says:

Line 3:
pacman() {
^-- SC2032: Use own script or sh -c '..' to run this from sudo.

Line 6:
sudo pacman "$@"
^-- SC2033: Shell functions can't be passed to external commands.

Here's what I wanted or expected to see:

No issues

@koalaman
Copy link
Owner

You're right of course, but it's hard for ShellCheck to know that the function isn't trying to reinvoke itself with sudo.

As mentioned in the wiki, you can quote the name (sudo "pacman" "$@") to make ShellCheck realize this isn't referencing the function, or you can ignore it with a directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants