Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am trying to create an alias for redirecting both standard output and standard error of gedit to /dev/null, whilst sending the command to background.

This works:

$ alias gedit='gedit $1 > /dev/null 2>&1'
$ gedit file.txt &

However, adding the background instruction & to the alias string fails to work because it gets immediately interpreted:

$ alias gedit='gedit $1 > /dev/null 2>&1 &'
[1]+  Done                    gedit > /dev/null 2>&1

How should I add this & background instruction to the alias command?

share|improve this question

marked as duplicate by Gilles, peterph, slm, Anthon, Zelda Jan 18 '14 at 6:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Is this for bash? – Timo Jan 17 '14 at 16:45
@Timo This would be for use in .bashrc. – Serge Stroobandt Jan 17 '14 at 17:30
up vote 4 down vote accepted

I don't think you can do this with an alias, but you can with a function in Bash.

$ gedit() { command gedit "$@" > /dev/null 2>&1 & }


$ gedit file.txt
[1] 24057


The function makes use of Bash's command command. This will invoke the actual executable with a given name, rather than call any aliases or functions that already exist. I opted to use $@ instead which will give you all the command line arguments passed instead of just the first with $1.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.