1. 基本概念(这是理解后面的知识的前提,请务必理解)
a. i/o重定向通常与 fd有关,shell的fd通常为10个,即 0~9; b. 常用fd有3个,为0(stdin,标准输入).1(stdout,标准输出).2(stderr,标准错误输出),默认与keyboard.monitor.monitor有关; c. 用 < 来改变读进的数据信道(stdin),使之从指定的档案读进; d. 用 > 来改变送出的数据信道(stdout, stderr),使之输出到指定的档案; e. 0 是 < 的默认值,因此 < 与 0<是一样的;同理,> 与 1> 是一样的; f. 在io重定向 中,stdout 与 stderr 的管道会先准备好,才会从 stdin 读进资料; g. 管道“|”(pipe line):上一个命令的 stdout 接到下一个命令的 stdin; h. tee 命令是在不影响原本 i/o 的情况下,将 stdout 复制一份到档案去; i. bash(ksh)执行命令的过程:分析命令-变量求值-命令替代(``与$( ))-重定向-通配符展开-确定路径-执行命令; j. ( ) 将 command group 置于 sub-shell 去执行,也称 nested sub-shell,它有一点非常重要的特性是:继承父shell的standard input, output, and error plus any other open file descriptors. k. exec 命令:常用来替代当前 shell 并重新启动一个 shell,换句话说,并没有启动子 shell.使用这一命令时任何现有环境都将会被清除,.exec 在对文件描述符进行操作的时候,也只有在这时,exec 不会覆盖你当前的 shell 环境. 2. 基本io cmd > file 把 stdout 重定向到 file 文件中 cmd >> file 把 stdout 重定向到 file 文件中(追加) cmd 1> fiel 把 stdout 重定向到 file 文件中 cmd > file 2>&1 把 stdout 与 stderr 一起重定向到 file 文件中 cmd 2> file 把 stderr 重定向到 file 文件中 cmd 2>> file 把 stderr 重定向到 file 文件中(追加) ... 下一页