Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash print stderr only, not stdout [duplicate]

Tags:

linux

bash

I want to lint a file, and print the stderr (error message), but do not print the stdout (saying the file is OK).

php -l "foo/bar.php"
  • If there are no errors, it prints a "No errors" message to stdout.
  • If there are errors, it prints a detailed message to stderr. I want only this one.

I figure it will be some magic with >&, but I never understood how those work.

What I want is to consume all stdout, keep stderr.

(Sorry if this is dulicate, but I haven't found any question exactly about this)

like image 981
MightyPork Avatar asked Oct 11 '22 16:10

MightyPork


1 Answers

Just send the stdout to null:

cmd > /dev/null

This retains stderr, but suppresses stdout.

like image 102
nneonneo Avatar answered Oct 16 '22 09:10

nneonneo