2015-12-28 16:32:49 +03:00
|
|
|
# printf
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
> Format and print text.
|
2015-12-28 16:32:49 +03:00
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Print a text message:
|
2015-12-28 16:32:49 +03:00
|
|
|
|
|
|
|
`printf {{"%s\n"}} {{"Hello world"}}`
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Print an integer in bold blue:
|
2015-12-28 16:32:49 +03:00
|
|
|
|
|
|
|
`printf {{"\e[1;34m%.3d\e[0m\n"}} {{42}}`
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Print a float number with the unicode Euro sign:
|
2015-12-28 16:32:49 +03:00
|
|
|
|
|
|
|
`printf {{"\u20AC %.2f\n"}} {{123.4}}`
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Print a text message composed with environment variables:
|
2015-12-28 16:32:49 +03:00
|
|
|
|
|
|
|
`printf {{"var1: %s\tvar2: %s\n"}} {{"$VAR1"}} {{"$VAR2"}}`
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Store a formatted message in a variable (does not work on zsh):
|
2015-12-28 16:32:49 +03:00
|
|
|
|
|
|
|
`printf -v {{myvar}} {{"This is %s = %d\n" "a year" 2016}}`
|