Often in some scripts, especially in the crontab call, the following form of command call
./t.sh >/dev/null 2>&1 first half./t.sh >/dev/null is easy to understand, so what's going on behind 2>&1?
To explain this problem, you still have to mention file redirection. We know that > and <is a file redirection. So what are 1 and 2? In the shell, each process is associated with three system files: standard input stdin, standard output stdout, and standard error stderr. The file descriptors for the three system files are 0, 1, and 2, respectively. So here 2 > & 1 means that the standard error is also output to the standard output.
The following is an example to show what effect 2>&1 has:
1234 $ cat ./t.sh#!/usr/bin/zshttttttecho "test"
t.sh contains two commands, where tttttt is a command that does not exist, and the execution will report an error. By default, the error will be output to stderr. Echo can be executed correctly and output string information to stdout. The standard output here has been redirected to /dev/null. Then standard error will also be output to /dev/null
Why 2>&1 should be written later?
First, ./t.sh >/dev/null 2>&1 redirects standard output to /dev/null, 2>&1 is the standard error copying standard output behavior That is, it is also redirected to file, the end result is that standard output and errors are redirected to file. ./t.sh 2>&1 >/dev/null The 2>&1 standard error copies the behavior of the standard output, but the standard output is still at the terminal. >/dev/null The output is redirected to /dev/null, but the standard error will still not be changed to /dev/null
The test results are as follows:
1234567891011121314 ➜ workspace ./t.sh ./t.sh:2: command not found: ttttttest➜ workspace ./t.sh >/dev/null./t.sh:2: command not found: ttttt ➜ workspace ./t.sh ./t.sh:2: command not found: ttttttest➜ workspace ./t.sh >/dev/null./t.sh:2: command not found: ttttt➜ workspace ./T.sh >/dev/null 2>&1➜ workspace ./t.sh 2>&1 /dev/null./t.sh:2: command not found: ttttttest
First, the installation of VirtualBox and expansion package installation steps is too simple, and wi
Linux has created a friendly environment that gives us the possibility to choose. For example, most
The original use of Tomcat in Linux does not use the newly created user created by the non-ROOT perm
The most popular Linux operating system distribution is Ubuntu. But this time we are running ASP.N
Linux (RedHat) network card, sound card configuration and installation entry
How to implement file sharing in VMWARE
How to optimize after the Linux server is installed?
Debian shows garbled (diamond, square) solution
Under linux rm delete non-empty directory
Common svn commands under Linux command line
Xwindow language selection under the Linux operating system
Novice trick: dd command skill under Linux operating system
How to check the shell type used by the Linux operating system
Linux I2C core, bus and device drivers
How to solve the Win8 control panel without BitLocker option?
Five changes in the media playback of Win10
Windows8.1 extended partition method
Teach you to delete the specified historical search record of the Vista system
How to add Notepad to the right-click menu in Win10
WinXP computer U disk repair tool Portfree Production Program usage
How to change the Windows version number of win7 system?
Tips for manually creating the start menu of Windows 8 [Photos] (1)
Win8 automatically updates the sound after installing the patch sometimes there is no solution