0

I have been using commands like

gedit some_script.pl & for many years.

However, I would like to force the program to automatically run in the background, so that I would get the command line back, and I don't type &.

How can I alter some setting somewhere so that when I type

gedit somescript.pl

will instead get the behavior of

gedit somescript.pl &?

con
  • 109
  • @muru, somewhat, but the answer given by terdon down below is significantly better than the answer on that link – con Apr 21 '20 at 15:57
  • My answer is almost identical to the other one. That's why I voted to close. We even gave the function the same (admittedly pretty obvious) name. The only extra bit mine has is how to keep the same command name, but that's not a very significant change. Am I missing something? – terdon Apr 21 '20 at 15:59
  • @terdon .bashrc was missing, I wouldn't have gotten that from the answer on that webpage. Your answer below is much better. – con Apr 21 '20 at 16:01
  • 1
    Ah, fair enough. I'll edit that into the other one then. – terdon Apr 21 '20 at 16:03

1 Answers1

1

Write a function. Add this to your ~/.bashrc (or equivalent if you're not using bash):

geditbg(){
    gedit "$@" &
}

Then, open a new terminal (or just run . ~/.bashrc) and you can now run geditbg somescript.pl and it will open in the background.

If you don't want to change the command name, you can do (change /usr/bin/gedit to whatever you get when you run which gedit on your system):

gedit(){
    /usr/bin/gedit "$@" &
}
terdon
  • 242,166