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