如何将函数/别名定义写入 Bash 历史记录



假设我有一个函数:

lsm(){
    ls ~/music
}

然后,假设我运行了它:

lsm

之后,如果我按"向上"键,那么我会看到lsm:我运行的最后一个命令。

但是,我的目标是让 Bash 历史记录写入函数/别名的完整扩展定义。

因此,如果我按"向上",我将在之前键入lsm后在 Bash 历史记录中看到ls ~/music

>@Cyrus有一个实用的建议:

使用history -s some stringsome string写入历史记录。

history
-s
    The *args* are added to the end of the history list as a single entry.

(来源:https://www.gnu.org/software/bash/manual/html_node/Bash-History-Builtins.html)