Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 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 at 16:45
    
@Timo This would be for use in .bashrc. –  Serge Stroobandt Jan 17 at 17:30

1 Answer 1

up vote 3 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 & }

Example

$ gedit file.txt
[1] 24057
$ 

Details

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.