Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1
2016-06-21 15:05
483 查看
http://unix.stackexchange.com/questions/70963/difference-between-2-2-dev-null-dev-null-and-dev-null-21
Just looking for the difference between
and their portability with
For background:
a number 1 = standard out (i.e. STDOUT)
a number 2 = standard error (i.e. STDERR)
if a number isn't explicitly given, then number 1 is assumed by the shell (bash)
First let's tackle the function of these. For reference see the
Advanced Bash-Scripting Guide.
The general form of this one is
"M".
The general form of this one is
"M", to
The general form of this one is
"N" are file descriptor numbers. It combines the output of file descriptors
"M" and "N" into a single stream.
This is just an abbreviation for
This is just an abbreviation for
This is just an abbreviation for
tcsh man page for more details.
Of the commands you asked about none are directly supported by csh/tcsh. You'd have to use different syntaxes to construct similar functions.
Just looking for the difference between
2>&-
2>/dev/null
|&
&>/dev/null
>/dev/null 2>&1
and their portability with
non-Bourne shellslike
tcsh,
mksh, etc.
For background:
a number 1 = standard out (i.e. STDOUT)
a number 2 = standard error (i.e. STDERR)
if a number isn't explicitly given, then number 1 is assumed by the shell (bash)
First let's tackle the function of these. For reference see the
Advanced Bash-Scripting Guide.
Functions
2>&-
The general form of this one is M>&-, where "M" is a file descriptor number. This will close output for whichever file descriptor is referenced, i.e.
"M".
2>/dev/null
The general form of this one is M>/dev/null, where "M" is a file descriptor number. This will redirect the file descriptor,
"M", to
/dev/null.
2>&1
The general form of this one is M>&N, where "M" &
"N" are file descriptor numbers. It combines the output of file descriptors
"M" and "N" into a single stream.
|&
This is just an abbreviation for 2>&1 |. It was added in Bash 4.
&>/dev/null
This is just an abbreviation for >/dev/null 2>&1. It redirects file descriptor 2 (STDERR) and descriptor 1 (STDOUT) to
/dev/null.
>/dev/null
This is just an abbreviation for 1>/dev/null. It redirects file descriptor 1 (STDOUT) to
/dev/null.
Portability to non-bash, tcsh, mksh, etc.
I've not dealt much with other shells outside ofcshand
tcsh. My experience with those 2 compared to bash's redirection operators, is that bash is superior in that regard. See the
tcsh man page for more details.
Of the commands you asked about none are directly supported by csh/tcsh. You'd have to use different syntaxes to construct similar functions.
相关文章推荐
- nodejs 路由
- nodejs 函数
- nodejs 事件
- CSS学习(一)
- 前端必读:浏览器内部工作原理
- css3
- nodejs 模块系统
- 安装 node
- Javascript点击其他任意地方隐藏关闭DIV实例
- 第五篇Bootstrap 排版
- h5手机网页的meta标签
- 欢迎使用CSDN-markdown编辑器
- EL表达式与JSTL(为空判断)
- Javascript随机标签云代码实例
- Bootstrap轮播插件简单使用方法介绍
- ES6 destructuring 解构赋值
- JS实现的跨浏览器解析XML文件实例
- js 设置radio默认选中
- 第四篇Bootstrap网格系统偏移列和嵌套列
- jquery ajax封装添加默认错误提示