搜索系统中所有名称为 test.sh
[jl@localhost ~]$ clear
[jl@localhost ~]$ find -name test.sh -print
./文档/test.sh
./下载/libevent-2.0.18-stable/test/test.sh
[jl@localhost ~]$
输入重定向是指命令所需的输入不是来自键盘 而是来自指定文件
输出重定向可以使命令的输出不显示在屏幕上而是写入到指定文件中
输入重定向例子:将test.sh作为wc操作的对象 也就是wc命令的输入
命令执行后显示文件test.sh 12行,54个单词 291个字符
[jl@localhost ~]$ cd 文档
[jl@localhost 文档]$ wc test.sh
12 54 291 test.sh
[jl@localhost 文档]$ vi test.sh
[jl@localhost 文档]$ cat test.sh
#!/bin/sh
sa="hello"
echo $sa
echo "the program $0 is now running"
echo "the first parameter was $2"
echo "the first parameter was $1"
echo "the parameter list was $*"
echo "the user home directory is $HOME"
echo "please enter a new ddd"
read sa
echo $sa
echo "the script is now over"
exit 0[jl@localhost 文档]$
将wc test.sh操作后显示在终端的结果重定向到文档目录下的test.txt文件中 如果test.txt已经存在 将被重写就是以前的都删除 然后重写入新的内容
用>>可讲第二次的输出追加到test.txt.中
[jl@localhost 文档]$ wc test.sh >test.txt
[jl@localhost 文档]$ cat test.txt
12 54 291 test.sh
[jl@localhost 文档]$
[jl@localhost 文档]$ wc test.sh >test.txt
[jl@localhost 文档]$ cat test.txt
12 54 291 test.sh
[jl@localhost 文档]$ wc test.sh >>test.txt
[jl@localhost 文档]$ cat test.txt
12 54 291 test.sh
12 54 291 test.sh
[jl@localhost 文档]$ wc test.sh >test.txt
[jl@localhost 文档]$ cat test.txt
12 54 291 test.sh
[jl@localhost 文档]$