简体   繁体   中英

Create a bash alias for typing out part of a command

I'm just learning Linux (v noob here). I'm trying to create an alias to type out part of a command in terminal.

I want the alias to type out transmission-remote -a ' and then stop. Not press return - just leave the cursor blinking ready for me to add the next part of the command.

I've tried using xclip but without luck. I keep getting 'Error: Can't open display: (null)'

Maybe my end game would be transmission-remote -a ' then paste clipboard copy and press return.

Hope you can help and thanks in advance!

Well that's exactly the work alias is good for. You can just use

$ alias your-neat-shortcut="transmission-remote -a"

and then anytime you want use it you can write the in my case not so shorter version

$ your-neat-shortuct --some --aditional stuff and files

and bash will expand it for you to

$ transmission-remote -a --some --aditional stuff and files

Note that this thing will work only in your current session and if you want to have it there every time you log in, you want to put it in the file ~/.bashrc where ~ is bash way to represent your home directory. This file runs every time you start a new terminal (actually whenever you start new bash) so you'll have the alias ready then.

In addition to @Ordoshsen's answer. The following alias can be used.

$ alias tra="tranmission-remote -a "

To use the alias everytime( possibly, you would like to):

1) You can copy the alias in .bashrc/.zshrc file( depending upon your shell).
2) Save the file and on the terminal do this on the home directory:

$ source .bashrc

I hope this will help. Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM