From d15a49df3bc65de2a125a3dbb072f078982ee141 Mon Sep 17 00:00:00 2001 From: rlscott Date: Wed, 24 Oct 2018 01:14:30 -0400 Subject: [PATCH] added printf.md and tested it --- _commands/basics/printf.md | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 _commands/basics/printf.md diff --git a/_commands/basics/printf.md b/_commands/basics/printf.md new file mode 100644 index 000000000..0525128ac --- /dev/null +++ b/_commands/basics/printf.md @@ -0,0 +1,71 @@ +--- +--- + +printf +------- + +print formatted ouput. +works like the c function of the same name. + +~~~ bash +printf FORMAT ARGS + +example: +printf "My name is \"%s\".\n The args can be nums %i." "Ryan" 2 + +output: +"My name is Ryan. +The args can be nums 2." +~~~ + + + +### Useful Options / Examples + +Like most commands printf also has a --help option +Some other interesting things to note: + +#### variable types + +%i = integer + +%d = decimal + +%o = octal + +%x = hex + +%u = unsigned int + +%c = character + +%s = string + +%f = float + +%e = scientific float (engineering) + +%p = pointer + +%% = percent sign + +#### modifiers + +You can modify the variables in different ways: +number = amount of space to occupy +\- = pad to the left +.number = max amount of characters to use + +##### Examples + +"%8s" "hi" + +" hi" + +"%-8s" "hi" + +"hi " + +"%.4s" "hello everyone" + +"hell"