Skip to content

Commit 8f01a84

Browse files
committed
add bash file redirection to /dev/null
1 parent a5af420 commit 8f01a84

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bash/dev_null

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# stdin ==> fd 0
4+
# stdout ==> fd 1
5+
# stderr ==> fd 2
6+
7+
8+
# the following commands all send stdout and stderr to /dev/null
9+
10+
# explicit
11+
rm nonexisting.txt 1> /dev/null 2> /dev/null
12+
13+
# fd 1 is the default stdout, so it can be ommited
14+
rm nonexisting.txt > /dev/null 2> /dev/null
15+
16+
# use a file descriptor duplication (>& 1) since /dev/null is already pointed
17+
# to by stdout 1
18+
rm nonexisting.txt 1> /dev/null 2>& 1
19+
20+
# shortened form of the common operation
21+
rm nonexisting.txt &> /dev/null

0 commit comments

Comments
 (0)