Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print terminal alias command as well as executing it

Tags:

bash

terminal

As a terminal noob, I've created aliases for pretty much everything I do. The problem is that I've started forgetting those few commands that I do know because of it. On top of that, I sometimes need to edit a variable in the previous command.

So what I'd like is if when I use an alias, the first line printed is the actual command it represents, then proceed to execute the command. Since pressing up and !! simply reprints the alias, I'm not too sure how to get a reference to the underlying command.

Thanks.

like image 478
willlma Avatar asked Mar 24 '14 14:03

willlma


People also ask

How do I print an alias in terminal?

just type alias in your terminal, that will show the entire list of alias and redirect that to file if you want to save.

How can I see alias commands?

To see a list of aliases set up on your linux box, just type alias at the prompt. You can see there are a few already set up on a default Redhat 9 installation. To remove an alias, use the unalias command.

How do I view bash aliases?

All you need to do is type alias at the prompt and any active aliases will be listed. Aliases are usually loaded at initialization of your shell so look in . bash_profile or . bashrc in your home directory.

Which command will display all the aliases that the system is currently using?

each subsequent command you use in the shell automatically becomes a tracked alias. Invoking alias with the -t option, but without any specified names, displays all currently defined tracked aliases with appropriate quoting. marks each alias name on the command line for export.


1 Answers

You can always use:

  • alias to list all your aliases, or
  • alias name to show the specification of the alias name.

So in fact you can define your alias as

alias myalias="alias myalias; <do stuff>"

I also think that chepner's answer with Alt-Control-e is more practical, but I am posting this for completeness.

like image 57
fedorqui 'SO stop harming' Avatar answered Nov 14 '22 18:11

fedorqui 'SO stop harming'