Every time starting the machine, I run the following program:
$ cat start.sh
#! /bin/bash
google-chrome &> /dev/null &
lantern &> /dev/null &
xdg-open . &> /dev/null &
emacs &> /dev/null &
code ~/Programs/ &> /dev/null &
xdg-open ~/Reference/topic_regex.md &> /dev/null &
Cumbersome &> /dev/null &
...
How could I shorten the logic?
The part
&> /dev/null
means output redirection. You can redirect multiple commands to the same file by grouping them into a block: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:... and then:
And because I'm lazy, I also wrote a shortcut for
xdg-open
:Because
xdg-open
expects exactly one argument, the functionxo
iterates over all given arguments and callsxdg-open
for each one separately.This allows for:
You could redirect the output for all subsequent commands with
I created a special file like
/dev/null
with a shorter path to shorten the redirection. I used/n
as the new file’s path:This way you can shorten the individual lines to e.g.:
Source: How to create /dev/null?
You could create a loop and give it the commands as arguments:
Note that this way exactly as with the subshell approach with curly braces it’s possible to sum up the outputs and redirect all of them at once.