LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1077|回复: 8

>和>&有什么区别?

[复制链接]
发表于 2006-1-6 16:56:09 | 显示全部楼层 |阅读模式
例如:
cat < readme > towrite
cat < readme >& towrite

二者功能上一样,执行过程上有区别么?
发表于 2006-1-6 22:44:43 | 显示全部楼层
[CODE]>&/<& means duplicate output/input not just redirect. But if towrite is not linked with file descriptor, then its probably just like the >file...
回复 支持 反对

使用道具 举报

发表于 2006-1-7 00:25:15 | 显示全部楼层
它们一样吗?
> filename
# The > truncates file "filename" to zero length.
# If file not present, creates zero−length file (same effect as 'touch').
# (Same result as ": >", above, but this does not work with some shells.)

>&j
# Redirects, by default, file descriptor 1 (stdout) to j.
# All stdout gets sent to file pointed to by j.
回复 支持 反对

使用道具 举报

发表于 2006-1-8 13:10:58 | 显示全部楼层
Post by 寂寞烈火
它们一样吗?

Well, only if >&n when n is a file descriptor. If n is just a regular file, I really don't see any difference.
  1. cat "abcd" >bb = cat "abcd" >&bb
复制代码
when bb is a regular file. But
  1. cat "abcd">3 != (exec 3>bb && cat "abcd" >&3)
复制代码
since the first 3 is a regular file and the second is a file descriptor...
回复 支持 反对

使用道具 举报

发表于 2006-1-8 17:04:32 | 显示全部楼层
Post by yongjian
Well, only if >&n when n is a file descriptor. If n is just a regular file, I really don't see any difference.
  1. cat "abcd" >bb = cat "abcd" >&bb
复制代码
when bb is a regular file. But
  1. cat "abcd">3 != (exec 3>bb && cat "abcd" >&3)
复制代码
since the first 3 is a regular file and the second is a file descriptor...

回复 支持 反对

使用道具 举报

发表于 2006-1-15 14:47:00 | 显示全部楼层
《Unix Shell编程》中说>& ,连接两个文件描述符使他们能指向同一个文件
回复 支持 反对

使用道具 举报

发表于 2006-1-16 09:54:25 | 显示全部楼层
Yes, regarding to file descriptor, the second one will be a copy of the original one. Look at
  1. ls -la /dev/fd/
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-1-17 20:32:13 | 显示全部楼层
>file,重定向到一个文件;
>&n,重定向到文件描述符。
回复 支持 反对

使用道具 举报

发表于 2006-1-19 14:24:08 | 显示全部楼层
Post by jiazhengw

>&n,重定向到文件描述符。

啥叫文件描述符????
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表