Bash 5 reference · Shell Builtins and Syntax
redirection (Bash syntax)
Send output to files, read input from files, merge stderr into stdout, and discard output with /dev/null.
Bash 5
Syntax
cmd > file cmd >> file cmd 2> file cmd &> file cmd 2>&1 cmd < file
Parameters
| Parameter | Description |
|---|---|
> |
Overwrite a file with stdout. |
>> |
Append stdout. |
2>&1 |
Send stderr where stdout goes. |
&> |
Both stdout and stderr to a file. |
<( cmd ) |
Process substitution: a command's output as a file. |
Examples
echo one > out.txt; echo two >> out.txt
ls nope 2> err.txt || true
wc -l < out.txt; grep -c 'nope' err.txt
Output
2 1
Run this on your computer — see “Get Started” for setup.
diff <(printf 'a\nb\n') <(printf 'a\nc\n') || true
Output
2c2 < b --- > c
Run this on your computer — see “Get Started” for setup.
Related
here-document· Feed multiple lines to a command with <<EOF; quote the marker to stop variable expansion, use <<- to strip tabs.- Bash Redirection and Pipes · tutorial