Shorten or merge multiple lines of `&> /dev/null &`
The part &> /dev/null
means output redirection. You can redirect multiple commands to the same file by grouping them into a block:
#! /bin/bash
{
google-chrome &
lantern &
xdg-open . &
emacs &
code ~/Programs/ &
xdg-open ~/Reference/topic_regex.md &
} &> /dev/null
The same thing, however, cannot be used to start individual commands in the background (&
). Putting &
after the block would mean running the whole block as a single script in the background.
I wrote a function and put it into my .bashrc
to run
things detached from my terminal:
detach ()
{
( "$@" &> /dev/null & )
}
... and then:
detach google-chrome
detach xdg-open ~/Reference/topic_regex.md
And because I'm lazy, I also wrote a shortcut for xdg-open
:
xo ()
{
for var in "$@"; do
detach xdg-open "$var";
done
}
Because xdg-open
expects exactly one argument, the function xo
iterates
over all given arguments and calls xdg-open
for each one separately.
This allows for:
detach google-chrome
xo . ~/Reference/topic_regex.md
You could redirect the output for all subsequent commands with
exec 1>/dev/null
exec 2>/dev/null