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
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.
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 theprintf
call. This means you can writeprintf -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 bevar="$(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'sprintf
.For bugs
shellcheck --version
or "online"): 0.9 (according to https://github.com/vscode-shellcheck/vscode-shellcheck/releases/tag/v0.29.2)Here's a snippet or screenshot that shows the problem:
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
The text was updated successfully, but these errors were encountered: