简体   繁体   中英

Save evaluated alias command in bash/zsh history

I am wondering if it would be possible to store evaluated commands in history instead of the alias. Especially with many user having their aliases it is difficult to have an overview of them when searching in history.

Example:

$ alias a2re="apache2ctl restart"
$ a2re
$ history
    1  a2re

Instead of:

$ history
    1 apache2ctl restart

Does anyone know if there is such an option for bash/zsh?

Not that I am aware of. bash , at least, records what is in the input buffer (after undergoing history expansion) just prior to hitting Enter to execute the command. One workaround is to tell the shell to expand the line before you commit to executing it. After you type the alias, type Meta - Control - e (where Meta is either your Alt or Esc key, depending on your setup). This will expand the line just like the shell would, but leaves the command on the command line for further editing before executing it by hitting Enter . Then the expanded form of the command is saved in your history.

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