How to append a string to a bash command line?

2

I am sure this is a recurrent question but I failed to find one that had an answer that would fit my problem.

What I want to do is something like this:

alias disexit = " & disown & exit"
gnome-calculator disexit

So it would run the command line

gnome-calculator & disown & exit

Therefore as a result it would have an instance of the calculator running and no terminal floating behind it, without having to manually write the whole thing.

If possible, I'd like to have that alias to be permanent.

Nerdy Cat

Posted 2017-09-20T16:47:33.493

Reputation: 21

For future reference, novice users etc. it's good to explain why your alias doesn't work. It's because alias name needs to be the first word of a simple command. – Kamil Maciorowski – 2017-09-22T05:45:12.853

Answers

3

That's not how alias works (and AFAIK what you want can't be done without modifying bash itself), but if you don't mind a slightly different syntax, you can add something like

disexit(){
    "$@" & disown & exit
}

to your .bashrc (to make this function permanent), and call it as

disexit gnome-calculator

Zombie Feynman

Posted 2017-09-20T16:47:33.493

Reputation: 95

Sorry, I didn't notice your answer appearing while I was typing mine. – AFH – 2017-09-20T17:17:16.087

0

You cannot do this with an alias. What you can do, however, is to code a function:

disexit() { "$1" & disown & exit; }

But you will need to call this the other way round:

disexit gnome-calculator

This is the closest you'll get to your requirements with bash syntax.

To make it permanently available, simply add the function definition to ~/.bashrc.

AFH

Posted 2017-09-20T16:47:33.493

Reputation: 15 470

0

Can't you just run nohup before the desired command? As in

nohup gnome-calculator &

Xen2050

Posted 2017-09-20T16:47:33.493

Reputation: 12 097