Between the % and the conversion character there may be, in order: -Ī minus sign. Conversion specificationsĮach conversion specification begins with a % and ends with a conversion character. ![]() will insert the value of the environment variable $LOGNAME, which is the username of whoever ran the command. For instance, the command printf "Hi, I'm %s.\n" $LOGNAME If used in a script, this argument can be set to a variable. For example, the output of the command in the above example can be altered by changing the argument, "John". The power of printf lies in the fact that for any given FORMAT string, the ARGUMENTs can be changed to affect the output. \n is the sequence for a newline character, and tells printf to begin a new line and continue the output from there. The sequence \" translates as a literal double-quote it is escaped with a backslash so that printf knows to treat it as a literal character, and not as the end of the FORMAT string. There are three escaped character sequences: two occurrences of \" and one occurrence of \n. There is one conversion specification: %s, which interprets the argument "John" as a string and inserts it into the output. Here, FORMAT is enclosed in double-quotes ( "). This command produces the output: My name is "John". Here is a quick example which uses these three types of objects: printf "My name is \"%s\".\nIt's a pleasure to meet you." "John" conversion specifications, which define the way the ARGUMENTs will be expressed as part of the output.interpreted character sequences, which are escaped with a backslash (" \").ordinary characters, which are copied verbatim to the output.The FORMAT string contains three types of objects: See the Format section, below.Įach ARGUMENT will be inserted into the formatted output according to the definition of FORMAT. printf OPTION Options FORMATįORMAT controls the output, and defines the way that the ARGUMENTs will be expressed in the output. ![]() It is a handy way to produce precisely-formatted output from numerical or textual arguments. Its roots are in the C programming language, which uses a function by the same name. Printf prints a formatted string to the standard output. Interpreted escaped character sequences.
0 Comments
Leave a Reply. |