The code directly includes variables in the printf format string, which can lead to unexpected behavior if the variable contains format specifiers or escape sequences. To fix this, use format specifiers like' %s' in the format string and pass variables as separate arguments to printf.
1
2# Noncompliant: Variables in format string can lead to unexpected behavior.
3name="Alice"
4printf "Welcome, $name!\n"1
2# Compliant: Safely handles variables, even if they contain format specifiers.
3name="Alice"
4printf "Welcome, %s!\n" "$name"