学习python风格, 优雅规范书写shell代码
操作 | 注释 |
---|---|
> | Overwrite |
1> | Redirect STDOUT to file |
2> | Redirect STDERR to file |
&> | Redirect all output to file |
>> | Append |
1>> | Append STDOUT to file |
2>> | Append STDERR to file |
3>> | Append all output to file |
2>&1 | Redirect STDERR to STDOUT |
<<WORD | Redirect multiple line from keyboard to STDIN with <<WORD |
COMMAND1 | COMMAND2
- send STDOUT of COMMAND1 to STDIN of COMMAND2 instead of the screen
- STDERR is not forwarded across pipes
COMMAND1 | tee [-a] FILE | COMMAND2
stores STDOUT of COMMAND1 in FILE, then pipes to COMMAND2
Examples:
echo > test
find /etc/ -name passwd &> find.all
find /etc/ -name passwd 2>&1 | head
2>&1: Redirects STDERR to STDOUT
- Useful for sending all output through a pipe
(cal 12 2018 ; cal 1 2019) | head -n 12
find /etc/ -name passwd &> /dev/null
find /etc/ -name passwd > find.out 2> find.err
find /etc/ -name passwd 2> /dev/null | tee find.out | head
cat > test.sh << EOF
原文:https://www.cnblogs.com/zakzhu/p/11615412.html