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

Relax SC2182 for bash, when printf -v is used #2650

Open
2 tasks done
jimbobmcgee opened this issue Dec 30, 2022 · 0 comments
Open
2 tasks done

Relax SC2182 for bash, when printf -v is used #2650

jimbobmcgee opened this issue Dec 30, 2022 · 0 comments

Comments

@jimbobmcgee
Copy link

Specifically for bash, printf has an extra option, -v which you can supply a variable name. This named variable is populated with the result of the printf call. This means you can write printf -vvar '%s x %s' "$1" "$2"; echo "$var".

Usually, the first arg to printf is a format string, so in POSIX shell, an equivalent might be var="$(printf '%s x %s' "$1" "$1")"; echo "$var".

SC2182 fires for bash if the first arg is -vvar, because -vvar does not contain any format string tokens. However, it is a valid argument to bash's printf.

For bugs

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

#!/bin/bash
printf -vvar '%s x %s' "$1" "$2"
echo "$var"

Here's what shellcheck currently says:

SC2182 (error): This printf format string has no variables. Other arguments are ignored.

Here's what I wanted or expected to see:

no error

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

1 participant