printf

From RaySoft

Write the formatted arguments to the standard output under the control of the format. The format is a character string which contains three types of objects: plain characters, which are simply copied to standard output, character escape sequences, which are converted and copied to the standard output, and format specifications, each of which causes printing of the next successive argument.[1]

Documentation

Syntax

printf [PARAMETER ...] FORMAT [ARGUMENT ...]

Parameters

-v NAME
Assign the output to shell variable NAME rather than display it on the standard output.

Examples

Print each element of an array without a loop
test=('1' 'a' 'foo bar')
printf '%s\n' "${test[@]}"

Output:

1
a
foo bar
Print the content of the IFS environment variable
printf '%q' "${IFS}"

Output:

$' \t\n'

References

  1. man 1 'bash'