# Echo built-in

The echo built-in prints its arguments.

## Syntax

- `echo [string…]`

The built-in treats all command line arguments as operands except for the options described below. Any word that cannot be parsed as an acceptable option is treated as an operand. Options must precede all operands. Syntax errors never happen in the echo built-in.

## Description

The echo built-in prints the operand strings followed by a newline to the standard output. The strings are each separated by a space.

### Escape sequences

The `ECHO_STYLE` variable and the `-e` option enable escape sequences that are replaced with corresponding characters:

`\a`

  Bell character (ASCII code: 7)

`\b`

  Backspace (ASCII code: 8)

`\c`

  Nothing. After this escape sequence, no characters are printed at all.

`\e`

  Escape character (ASCII code: 27)

`\f`

  Form feed character (ASCII code: 12)

`\n`

  Newline character (ASCII code: 10)

`\r`

  Carriage return character (ASCII code: 13)

`\t`

  Horizontal tab character (ASCII code: 9)

`\v`

  Vertical tab character (ASCII code: 11)

`\\`

  Backslash

`\0xxx`

  Character whose code is xxx, where xxx is an octal number of at most three digits.

When escape sequences are not enabled, they are just printed intact.

### `ECHO_STYLE` variable

The `ECHO_STYLE` variable defines which options are accepted and whether escape sequences are enabled by default. The variable value should be set to one of the following:

`SYSV`
`XSI`

  No options are accepted. Escape sequences are always enabled.

`BSD`

  The `-n` option is accepted. Escape sequences are never enabled.

`GNU`

  The `-n`, `-e`, and `-E` options are accepted. Escape sequences are not enabled by default, but can be enabled by the `-e` option.

`ZSH`

  The `-n`, `-e`, and `-E` options are accepted. Escape sequences are enabled by default, but can be disabled by the `-E` option.

`DASH`

  The `-n` option is accepted. Escape sequences are always enabled.

`RAW`

  No options are accepted. Escape sequences are never enabled.

When the `ECHO_STYLE` variable is not set, it defaults to `SYSV`.

## Options

`-n`

  Do not print a newline at the end.

`-e`

  Enable escape sequences.

`-E`

  Disable escape sequences.

## Exit status

The exit status of the echo built-in is zero unless there is any error.

## Notes

The POSIX standard does not define the `ECHO_STYLE` variable nor any options for the built-in. According to POSIX, the behavior of the built-in is implementation-defined when the first argument is `-n` or when any argument contains a backslash. For maximum portability, the printf built-in should be preferred over the echo built-in.

Although many values for the `ECHO_STYLE` variable are defined on the basis of other existing implementations, yash is not intended to exactly imitate those originals. Zsh’s echo built-in interprets a single hyphen argument as a separator between options and operands. Yash does not support such use of hyphen.