Home > Enterprise >  That is so strange ,WHY
That is so strange ,WHY

Time:11-22

It is so strange!!!The frist command work well ,but the second output error.forgive my poor english

 1.printf '%d\n' "'a"
 2.printf '%d\n' "a"

enter image description here

CodePudding user response:

From the bash man page, (in the pretty lengthy section titled SHELL BUILTIN COMMANDS) about command printf:

Arguments to non-string format specifiers are treated as C constants, except that a leading plus or minus sign is allowed, and if the leading character is a single or double quote, the value is the ASCII value of the following character.

So you would also have succeeded with

printf '%d\n' \"a
  • Related