Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Suppose I wanted to kill firefox , I just write pidof fi(press tab)refox (appears on its own) , then I write ' kill 'id given by pidof' ' on terminal.

I know that I can write 'kill `pidof firefox` ' but the autocomplete does not work . So I wanted a command like mykill firefox (on which tab completion also work) which on the background runs 'kill `pidof firefox` '

mykill process name (with tab completion) -> kill `pidof process name`

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Your best bet would to just use the pkill command instead. It can be found in the procps package. You use it like so:

pkill fir<tab>
pkill firefox

To get completion for nested commands, your shell (bash) needs to be smart and enable autocompletion in those scenarios. Unforunately, it looks like it does not. I believe the alternative shell, fish, does.

share|improve this answer
    
I agree on this but there is 1 difference that could matter: you kill all firefoxes and TS method kills 1. There could be 2+ running ;) –  Rinzwind Jun 6 at 19:29
    
Thanx for your answer @Cameron , will surely use it but I want to learn how to implement auto complete in shell using bash so hoping that another answer answering that also appears :) I would have also upvoted your answer if i had more than 15 reputation :P –  aabhas Jun 6 at 19:46
    
Your shell allows you to create functions in your .bashrc which are available for use just like regular commands. I do not think bash supports autocomplete for functions, though. fish does not either. –  CameronNemo Jun 8 at 3:02
    
There are pkill and killall. They can act in a similar way. To spot the differences between them you may give a look to this answer or to the other of the post. –  Hastur Jun 11 at 20:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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