You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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/bashpacman() {
if!command pacman "$@";thenecho"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
The text was updated successfully, but these errors were encountered:
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.
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
Here's a snippet or screenshot that shows the problem:
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
The text was updated successfully, but these errors were encountered: