1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/common/printf.md
Fazle Arefin a2ea10ad8b
printf: edit page (#12449)
* printf: edit page

* Update pages/common/printf.md

Co-authored-by: Muhammad Falak R Wani <falakreyaz@gmail.com>

* printf: update example

---------

Co-authored-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2024-03-03 14:47:08 +01:00

715 B

printf

Format and print text. More information: https://www.gnu.org/software/coreutils/printf.

  • Print a text message:

printf "{{%s\n}}" "{{Hello world}}"

  • Print an integer in bold blue:

printf "{{\e[1;34m%.3d\e[0m\n}}" {{42}}

  • Print a float number with the Unicode Euro sign:

printf "{{\u20AC %.2f\n}}" {{123.4}}

  • Print a text message composed with environment variables:

printf "{{var1: %s\tvar2: %s\n}}" "{{$VAR1}}" "{{$VAR2}}"

  • Store a formatted message in a variable (does not work on zsh):

printf -v {{myvar}} {{"This is %s = %d\n" "a year" 2016}}

  • Print a hexadecimal, octal and scientific number:

printf "{{hex=%x octal=%o scientific=%e}}" 0x{{FF}} 0{{377}} {{100000}}