Shell Redirections ↔ Quick Guide
File descriptors:
stdin
: 0stdout
: 1stderr
: 2
This trick can be used to take multi-line input in scripts.
#!/usr/bin/env bash
echo -e "Enter Commit Message (Ctrl+d when done):"
msg=$(</dev/stdin)
echo $msg
- 1.Use
2>
. Compatible with bothbash
andsh
- 1.With
bash
, usesome_command &> /dev/null
- 2.With
sh
,some_command > where-to-redirect 2>&1# orsome_command 2>&1 > stdout_and_err - 3.If you want to capture standard output/error separately,$ some_command 1>output.txt 2>error.txt