file descriptor是个什么东西```~
举例说下~~~~~
谢谢~~~~~~~
| iricyan 回复于:2003-11-19 23:42:13 |
| 0
1 2 |
| 红头发 回复于:2003-11-20 06:45:54 |
| whut?
012? |
| guchengman 回复于:2003-11-20 18:33:04 |
| 0是标准输出,
1是标准输入. 2是标准错误, 如: cat </etc/passwd 能够查看该文档, 其原理是利用输入重定向, 但其完整写法应该是: cat 0 </etc/passwd,0在这被省略掉了. ls -l>a.txt能够把ls命令保存到一个文档当中, 在这完整写法应该是 ls -l 1>a.txt 当您运行ls -l /errdir 时会有错误提示, 我们能够用标准错误重定向来把错误提示保存到一个文档中或丢弃. ls -l /errdir 2>/tmp/a.txt 把错误保存在/tmp/a.txt文档中. ls -l /errdir 2>/dev/null 把错误提示丢弃,也即不显示. |
| mmmmn 回复于:2003-11-20 18:44:38 |
| 真是开玩笑,文档句柄能是这东西? |
| 红头发 回复于:2003-11-20 19:18:29 |
| 谢谢我消化下~~~~ |
| guchengman 回复于:2003-11-20 21:48:38 |
| [quote:8544bbfcb5="mmmmn"]真是开玩笑,文档句柄能是这东西?[/quote:8544bbfcb5]
其实我也是有疑问, 但是在书上只是写了 1 2 3 之类的东东, 加上前者所说, 我就因此回复, 还请大侠出来分析一下. |
| iricyan 回复于:2003-11-20 22:38:59 |
ops:
写错了。 |
| laoxia 回复于:2003-11-21 06:40:17 |
| [quote:af318e44a5="guchengman"]0是标准输出,
1是标准输入. 2是标准错误, 如: cat </etc/passwd 能够查看该文档, 其原理是利用输入重定向, 但其完整写法应该是: cat 0 </etc/passwd,0在这被省略掉了. ls -l>a.txt能够把..........[/quote:af318e44a5]This is right. file descriptor 0, 1, 2 are not all of the descriptors. but they are the most commonly used ones. |
| laoxia 回复于:2003-11-21 06:49:50 |
| [b:8ee48ac867]Standard In, Standard Out, and Standard Error[/b:8ee48ac867]
When writing shell scripts, you can control input/output redirection. Input redirection is the ability to force a command to read any necessary input from a file instead of from the keyboard. Output redirection is the ability to send the output from a command into a file or pipe instead of to the screen. Each process created by a shell script begins with three [color=red:8ee48ac867]file descriptors[/color:8ee48ac867] associated with it, as shown in Figure 16-1. These [color=red:8ee48ac867]file descriptors[/color:8ee48ac867]—standard input, standard output, and standard error—determine where input to the process comes from, and where the output and error messages are sent. Standard input (STDIN) is always file descriptor 0. Standard input is the place where the shell looks for its input data. Usually data for standard input comes from the keyboard. You can specify standard input to come from another source using input/output redirection. Standard output (STDOUT) is always [color=red:8ee48ac867]file descriptor[/color:8ee48ac867] 1. Standard output (default) is the place where the results of the execution of the program are sent. Usually, the results of program execution are displayed on the terminal screen. You can redirect standard output to a file, or suppress it completely by redirecting it to /dev/null.Standard error (STDERR) is always [color=red:8ee48ac867]file descriptor [/color:8ee48ac867]2. Standard error is the place where error messages are sent as they are generated during command processing. Usually, error messages are displayed on the terminal screen. You can redirect standard error to a file, or suppress it completely by redirecting it to /dev/null. You can use the [color=red:8ee48ac867]file descriptor [/color:8ee48ac867]numbers 0 (standard input), 1 (standard output), and 2 (standard error) together with the redirection metacharacters to control input and output in the Bourne and Korn shells. Table 16-7 shows the common ways you can redirect file descriptors. [i:8ee48ac867]Table 16-7 Bourne and Korn Shell Redirection [/i:8ee48ac867] -------------------------------------------------------------------------------- Description Command [color=red:8ee48ac867]Take STDIN from file <file, or 0<file Redirect STDOUT to file > file, or 1>file Redirect STDERR to file 2> file Append STDOUT to end of file >> file Redirect STDERR to STDOUT 2>&1 Pipe standard output of cmd1 as standard input to cmd2 cmd1 | cmd2 Use file as both STDIN and STDOUT <> file Close STDIN <&- Close STDOUT >&- Close STDERR 2>&- [/color:8ee48ac867]
文章整理:西部数码--专业提供域名注册、虚拟主机服务 相关文章
热点关注
IDC资讯
虚拟主机
域名注册
托管租用
vps主机
智能建站
网站运营 建站经验 策划盈利 搜索优化 网站推广 免费资源 网站联盟 联盟新闻 联盟介绍 联盟点评 网赚技巧 行业资讯 业界动态 搜索引擎 网络游戏 门户动态 电子商务 广告传媒 网络编程 Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它 服务器技术 Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护 软件技巧 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷 Internet Explorer 网页制作 FrontPages Dreamweaver Javascript css photoshop fireworks Flash 程序设计 Java技术 C/C++ VB delphi 网络知识 网络协议 网络安全 网络管理 组网方案 Cisco技术 操作系统 Win2000 WinXP Win2003 Mac OS Linux FreeBSD |

ops:


