在一些用于系统管理的脚本中,把标准输出和标准出错输出 一起重定向到 /dev/null
比如: 在/etc/rc.d/rc.sysinit 中有这样的一段:
if [ ! -e /proc/mounts ]; then mount -n -t proc /proc /proc mount -n -t sysfs /sys /sys >/dev/null 2>&1 fi
现在的问题是,也可以这样表达 .......... mount -n -t sysfs /sys /sys &>/dev/null ...........
而且也简便一些,为什么几乎所有的系统脚本中都用前一种方式呢?
2010/12/15 David Young dhyang555@gmail.com:
在一些用于系统管理的脚本中,把标准输出和标准出错输出 一起重定向到 /dev/null
比如: 在/etc/rc.d/rc.sysinit 中有这样的一段:
if [ ! -e /proc/mounts ]; then mount -n -t proc /proc /proc mount -n -t sysfs /sys /sys >/dev/null 2>&1 fi
现在的问题是,也可以这样表达 .......... mount -n -t sysfs /sys /sys &>/dev/null ...........
而且也简便一些,为什么几乎所有的系统脚本中都用前一种方式呢?
看看这个会不会有帮助: http://www.perlmonks.org/?node_id=716315 好像是有些程序里面会不识别&>的方式?
Chinese mailing list Chinese at lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/chinese
2010/12/15 xie yunpeng woqimingweipeng@gmail.com
莫非在别的unix类的系统中还有别的输出?
你用過 OSX (另一種 unix)就會發現現在 LInux 很多接近理所當然的用法,在上面都不能應用。
K410
2010-12-15(Wednesday) 18:04:48 +0800, David Young dhyang555@gmail.com:
在一些用于系统管理的脚本中,把标准输出和标准出错输出 一起重定向到 /dev/null
比如: 在/etc/rc.d/rc.sysinit 中有这样的一段:
if [ ! -e /proc/mounts ]; then mount -n -t proc /proc /proc mount -n -t sysfs /sys /sys >/dev/null 2>&1 fi
现在的问题是,也可以这样表达 .......... mount -n -t sysfs /sys /sys &>/dev/null ...........
而且也简便一些,为什么几乎所有的系统脚本中都用前一种方式呢?
这个原因很简单,因为 &> 是 bash 的扩展,并不符合 POSIX 标准。不用你 换其他 Shell 执行那段脚本试试看。
chinese@lists.fedoraproject.org