Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

added printf.md and tested it #694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions _commands/basics/printf.md
Original file line number Diff line number Diff line change
@@ -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."
~~~

<!--more-->

### 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"