Linux/BASH: Difference between revisions
< Linux
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
== Shebang == | == Shebang == | ||
* <pre>#!/bin/bash</pre> | * <pre>#!/bin/bash</pre> | ||
== Output & Piping == | |||
* Command output | |||
<pre> | |||
command > file.txt # redirect output | |||
command >> file.txt # append to file | |||
command &> file.txt # stdout and stderr to file | |||
command &>> file.txt # stdout and stderr append to file | |||
command 2> file.txt # stderr to file | |||
command 2>> file.txt # stderr append to file | |||
command | tee -a file.txt # stdout to terminal and file (append) | |||
command |& tee -a file.txt # stdout+stderr to terminal and file (append) | |||
</pre> | |||
== If == | == If == |
Revision as of 08:08, 30 August 2020
Shebang
#!/bin/bash
Output & Piping
- Command output
command > file.txt # redirect output command >> file.txt # append to file command &> file.txt # stdout and stderr to file command &>> file.txt # stdout and stderr append to file command 2> file.txt # stderr to file command 2>> file.txt # stderr append to file command | tee -a file.txt # stdout to terminal and file (append) command |& tee -a file.txt # stdout+stderr to terminal and file (append)
If
if [ condition ] then command1 else command2 fi