Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simply forking and redirecting the output of a command to /dev/null

I frequently execute from a shell (in my case Bash) commands that I want to fork immediately and whose output I want to ignore. So frequently in fact that I created a script (silent) to do it:

#!/bin/bash
$@ &> /dev/null &

I can then run, e.g.

silent inkscape myfile.svg

and my terminal will not be polluted by the debug output of the process I just forked.

I have two questions:

  1. Is there an "official" way of doing this?, i.e. something shorter but equivalent to &> /dev/null & ?

  2. If not, is there a way I can make tab-completion work after my silent command as if it weren't there ? To give an example, after I've typed silent inksc, I'd like bash to auto-complete my command to silent inkscape when I press [tab].

like image 334
Philippe Avatar asked Dec 08 '11 14:12

Philippe


Video Answer


1 Answers

aside: probably want to exec "$@" &> /dev/null & in your silent script, to cause it to discard the sub-shell, and the quotes around "$@" will keep spaces from getting in the way.

As for #2: complete -F _command silent should do something like what you want. (I call my version of that script launch and have complete -F launch in my .bash_profile)

like image 87
BRPocock Avatar answered Nov 11 '22 17:11

BRPocock