Difference between 2>&-, 2>/dev/null, |&, &>/dev/null, >/dev/null, 2>&1
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)
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>&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.
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
.
>/dev/null
This is just an abbreviation for 1>/dev/null
.
It redirects file descriptor 1 (STDOUT) to /dev/null
.
&>/dev/null
This is just an abbreviation for 2>&1
>/dev/null
. It too was added in Bash 4. It redirects file descriptor 2 (STDERR) and descriptor 1 (STDOUT) to /dev/null
.
Portability to non-bash, tcsh, mksh, etc.
I've not dealt much with other shells outside of csh
and 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.
相關文章
- 2>/dev/null和>/dev/null 2>&1和2>&1>/dev/null的區別devNull
- ">/dev/null 2>&1 "是什麼意思devNull
- shell指令碼中/dev/null 2>&1詳解指令碼devNull
- Linux下" >/dev/null 2>&1 "相關知識說明LinuxdevNull
- /dev/null和標準*使用devNull
- Shell指令碼中的 /Dev/Null 用途指令碼devNull
- BEA dev2dev 線上dev
- 【Postopia Dev Log】Day 2dev
- 關於 /dev/null 差點直播吃鞋的一個小問題devNull
- npm run dev 換成 pm2NPMdev
- 【NULL】Oracle null值介紹NullOracle
- 【Postopia Dev Blog】day 1dev
- DEV dxTabbedMDIManagerdev
- MySQL中IS NULL、IS NOT NULL、!=不能用索引?胡扯!MySqlNull索引
- PropertyChanged == nullNull
- MySQL NULLMySqlNull
- MySQL null值儲存,null效能影響MySqlNull
- Python Web DevPythonWebdev
- NULL列時,如何使得IS NULL或者IS NOT NULL可以使用索引來提高查詢效率Null索引
- MYSQL timestamp NOT NULL插入NULL的報錯問題MySqlNull
- 為什麼索引無法使用is null和is not null索引Null
- null與indexNullIndex
- null 和 undefinedNullUndefined
- Insider Dev Tour(2018.06.28)IDEdev
- Elastic_Dev_ToolsASTdev
- 面試題((A)null).fun()——java中null值的強轉面試題NullJava
- SCSS Null 型別CSSNull型別
- null in ABAP and nullpointer in JavaNullJava
- MySQL null和''分析MySqlNull
- undefined與null與?. ??UndefinedNull
- dart系列之:和null說再見,null使用最佳實踐DartNull
- MySQL NOT NULL列用 WHERE IS NULL 也能查到資料的原因MySqlNull
- 從Node到Deno - DEVdev
- NPM run dev 報錯NPMdev
- dotnet dev-certs httpsdevHTTP
- DEV c++ 的配置devC++
- application.yml&dev&redisAPPdevRedis
- null調整為not null default xxx,不得不注意的坑Null
- Sublime Text 4 Dev中文破解版+Sublime Text 4 Dev啟用碼dev