#输入输出重定向: Unix gets input from stdin by default, stdout output, input device is keyboard, output device is terminal
#输出重定向: The clear output can be not only the monitor, but also the transfer to the file, which is called the output redirection
#输出重定向会覆盖文件内容
#输出重定向语法: Command > File
1 Echo who > Users #在当前目录创建一个users文件 and writes the current user name to get #
#输入重定向语法: Command < file
#重定向深入讲解
#一般情况Unix/linux command will open three files when run
#标准输入文件stdin: File descriptor 0,unix reads data from stdin by default
#标准输出文件stdout: File descriptor is 1,unix default output data from stdout
#标准错误文件stderr: The file descriptor 2,unix will write an error message to the stderr stream
#默认情况下, command > file redirect stdout to File,command < file to redirect stdin to file
#如果希望stderr重定向到file: Command 2 > File
#如果希望stderr追加到file末尾: Command 2 >> file
#如果希望stdout和stderr合并后重定向到file: Command > File 2>&1 or Command > file 2>&1
#如果希望stdin和stdout都重定向: Command < file1 > File2
#command命令将stdin重定向到file1, stdout redirect to File2
#查看全部可用的重定向命令列表获取更多 ~/Desktop/blog/shell#
#Here A special redirection method in Document:shell: The form is as follows:
#command << delimiter
# document
#delimiter
#它的作用是将两个delimiter之间的内容document作为输入传递给command
#注意: The end of the delimiter must shelf write
#开始的delimiter前后的空格会被忽略掉 For example
1 cat << EOF2this34a test5 Eof
#计算行数例子如下: Terminal input: Results: 3
1 WC -L << EOF2this34a test 5 EOF
#将document保存到当前目录的test. txt files
1 cat << EOF > test.txt2file is created automaticallyfrom3 a shell script4 EOF
#/dev/null: If you want to execute a command, but do not want to output the results at the terminal, you can redirect the output to/dec/null
# command >/dev/null
#这是一个特殊的文件, writing its contents is discarded and the content is not read.
#但它非常有用, redirect the command output to it, to suppress the output effect
#如果希望屏蔽stdout和stderr: command >/dev/null 2>&1
#像其他语言一样, the shell can contain external scripts
#包含脚本可以使用:. FileName or source filename
#创建一个被调用脚本subscript. Sh:url= "Www.baidu.com"
#创建主文件main. Sh
1 . ./subscript. SH 2 echo ${url}
#赋予main +x permissions and executes, output www.baidu.com
#被包含脚本不需要执行权限
Linux Gvim shell input and output redirection