Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference-redirecting to bit bucket(aka /dev/null) vs closing the file descriptor

Is there any difference between the below two commands?

ls -l some_non_existing_file 2>/dev/null

and

ls -l some_non_existing_file 2>&-

Both seems to work but I have seen only the first one being used practically so far.

like image 528
toddlermenot Avatar asked Oct 27 '25 14:10

toddlermenot


1 Answers

Attempts by the program to output data to stderr will fail in the second case with EBADF. Whether the program cares or not is a separate issue.

like image 92
Ignacio Vazquez-Abrams Avatar answered Oct 29 '25 05:10

Ignacio Vazquez-Abrams