Skip to content

Instantly share code, notes, and snippets.

@LeoHuckvale
Last active August 29, 2015 14:12
Show Gist options
  • Save LeoHuckvale/90477374d99c84cfbfd8 to your computer and use it in GitHub Desktop.
Save LeoHuckvale/90477374d99c84cfbfd8 to your computer and use it in GitHub Desktop.
Run a command in shell with stdout and stderr redirected to null
#!/bin/sh
# Run a command with stdout and stderr redirected to null
# Usage:
# $ quiet foo
# Check command is valid
command -v $1 >/dev/null 2>&1 || { echo >&2 "$1: command not found"; exit 1; }
# Run command with all arguments
$@ >/dev/null 2>&1
@LeoHuckvale
Copy link
Author

Installation:

$ cp quiet.sh /some/path/to/personal/bin/quiet
$ chmod 755 /some/path/to/personal/bin/quiet

@LeoHuckvale
Copy link
Author

This doesn't work with filenames with spaces, e.g.:

$ quiet evince some\ filename\ with\ spaces.pdf &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment