Skip to content

Output

Print text to the pipeline with optional escape sequence expansion.

echo [OPTIONS] [STRING...]
FlagDescriptionExample
-nSuppress trailing newlineecho -n 'no newline'
-eEnable interpretation of escape sequencesecho -e 'line1\nline2'
-EDisable interpretation of escape sequences (default)echo -E 'literal \n'

When -e is active, the following sequences are expanded:

SequenceMeaning
\nNewline
\tHorizontal tab
\rCarriage return
\aAlert (bell)
\bBackspace
\fForm feed
\vVertical tab
\\Literal backslash

PsBash.TextOutput with a single property:

PropertyTypeDescription
BashTextstringThe formatted output text (includes trailing newline unless -n is used)

Basic output:

Terminal window
echo 'Hello, world!'
Hello, world!

Multiple arguments are joined with spaces:

Terminal window
echo one two three
one two three

Suppress trailing newline with -n:

Terminal window
echo -n 'prompt> '
prompt>

The output has no trailing newline, so subsequent output appears on the same line.

Escape sequences with -e:

Terminal window
echo -e 'column1\tcolumn2\nrow1\trow2'
column1 column2
row1 row2

Access the object programmatically:

Terminal window
$out = echo -n 'hello'
$out.BashText # "hello"
$out.BashText.Length # 5
Terminal window
echo -e 'hello\tworld'
# hello world

Bash echo behavior varies across implementations (GNU coreutils vs built-in). The -e flag is not POSIX-standard; some shells enable escapes by default.


Format and print text using C-style format specifiers.

printf FORMAT [ARGUMENTS...]

The FORMAT string is required. If no ARGUMENTS are provided, format specifiers consume nothing and produce empty output for that position.

SpecifierDescriptionExample
%sStringprintf '%s' 'hello' produces hello
%dDecimal integerprintf '%d' 42 produces 42
%fFloating-point (6 decimal places)printf '%f' 3.14 produces 3.140000
%%Literal percent signprintf '100%%' produces 100%

The format string automatically expands the same escape sequences as echo -e:

SequenceMeaning
\nNewline
\tHorizontal tab
\rCarriage return
\aAlert (bell)
\bBackspace
\fForm feed
\vVertical tab
\\Literal backslash

printf automatically converts string arguments to the type required by the format specifier:

  • Arguments that parse as integers are passed as [int] to %d
  • Arguments that parse as decimals are passed as [double] to %f
  • All other arguments remain as [string]

PsBash.TextOutput with a single property:

PropertyTypeDescription
BashTextstringThe formatted output text (no automatic trailing newline)

Simple string formatting:

Terminal window
printf 'Hello, %s!\n' 'world'
Hello, world!

Multiple arguments with mixed types:

Terminal window
printf 'Name: %s, Age: %d, Score: %f\n' 'Alice' 30 95.5
Name: Alice, Age: 30, Score: 95.500000

Tab-separated table:

Terminal window
printf '%s\t%s\t%s\n' 'Name' 'Role' 'Team'
printf '%s\t%s\t%s\n' 'Alice' 'Dev' 'Platform'
printf '%s\t%s\t%s\n' 'Bob' 'QA' 'Platform'
Name Role Team
Alice Dev Platform
Bob QA Platform

Literal percent sign:

Terminal window
printf 'Disk usage: %d%%\n' 73
Disk usage: 73%

Access the object programmatically:

Terminal window
$out = printf '%s-%d' 'build' 42
$out.BashText # "build-42"

Calling printf with no arguments throws an error:

Terminal window
printf
# printf: usage: printf format [arguments]
Terminal window
printf 'Name: %s, Count: %d\n' 'items' 5
# Name: items, Count: 5

Bash printf supports the full POSIX set of specifiers including %x, %o, %e, %g, width modifiers, and precision. It also reuses the format string if there are more arguments than specifiers.