拓展阅读

linux Shell 命令行-00-intro 入门介绍

linux Shell 命令行-02-var 变量

linux Shell 命令行-03-array 数组

linux Shell 命令行-04-operator 操作符

linux Shell 命令行-05-test 验证是否符合条件

linux Shell 命令行-06-flow control 流程控制

linux Shell 命令行-07-func 函数

linux Shell 命令行-08-file include 文件包含

linux Shell 命令行-09-redirect 重定向

重定向

命令 描述
command > file 输出重定向到文件
command < file 输入重定向自文件
command » file 输出追加重定向到文件
n > file 文件描述符 n -> 文件
n » file 文件描述符 n 追加 -> 文件
n >& m 输出文件 mn 合并
n <& m 输入文件 mn 合并
« tag 输入重定向,标记之间的内容作为输入

文件描述符

  [plaintext]
1
2
3
0 //标准输入 1 //标准输出 2 //标准错误输出

输出重定向

  [bash]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
houbinbindeMacBook-Pro:shell houbinbin$ ls > ls_file houbinbindeMacBook-Pro:shell houbinbin$ cat ls_file break.sh case.sh continue.sh data.sh diff_demo.sh file_test_oper.sh for.sh funcWithParam.sh funcWithReturnVal.sh function.sh hello.sh hello_name.sh if_else.sh include.sh ls_file num_oper.sh readonly_var.sh special_var.sh test_file.sh test_num.sh unset_var.sh use_var.sh while.sh

输入重定向

我们想计算文件 ls_file 的行数

  [bash]
1
2
houbinbindeMacBook-Pro:shell houbinbin$ wc -l ls_file 23 ls_file

参考资料

https://www.runoob.com/linux/linux-shell.html