From 395e8eaa54f73e652d0d408f8babf7cd7c85248b Mon Sep 17 00:00:00 2001 From: Jose Ricardo Ziviani Date: Mon, 28 Dec 2015 11:32:49 -0200 Subject: [PATCH] Add a new page about the printf command - printf is a bash command that acts like C's printf, supporting format strings and modifiers. Signed-off-by: Jose Ricardo Ziviani --- pages/common/printf.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 pages/common/printf.md diff --git a/pages/common/printf.md b/pages/common/printf.md new file mode 100644 index 000000000..a3dc7efa2 --- /dev/null +++ b/pages/common/printf.md @@ -0,0 +1,23 @@ +# printf + +> Format and print text + +- 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}}`