mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2059 (markdown)
10
SC2059.md
10
SC2059.md
@@ -31,15 +31,17 @@ The second writes ``bash: printf: `\': invalid format character``
|
|||||||
Sometimes you may actually want to interpret data as a format string, like in:
|
Sometimes you may actually want to interpret data as a format string, like in:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
hexToAscii() { printf "\x$1"; }
|
octToAscii() { printf "\\$1"; }
|
||||||
hexToAscii 21
|
octToAscii 130
|
||||||
```
|
```
|
||||||
|
|
||||||
or when you have a pattern in a variable:
|
In Bash, Ksh and BusyBox, there's a `%b` format specifier that expands escape sequences without interpreting other format specifiers: `printf '%b' "\\$1"`. In POSIX, you can instead [[ignore]] this warning.
|
||||||
|
|
||||||
|
Other times, you might have a pattern in a variable:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
filepattern="file-%d.jpg"
|
filepattern="file-%d.jpg"
|
||||||
printf -v filename "$filepattern" "$number"
|
printf -v filename "$filepattern" "$number"
|
||||||
```
|
```
|
||||||
|
|
||||||
These are valid use cases with no useful rewrites. Please [[ignore]] the warnings with a [[directive]].
|
This has no good rewrite. Please [[ignore]] the warning with a [[directive]].
|
Reference in New Issue
Block a user