如何将 bash 中的特定输入映射到命令?

How do I map a certain input in bash to a command?

所以我想知道是否可以将某个输入映射到 gnome 终端中的命令。例如,当我在命令shell中输入"foo"时,它会自动执行某个命令,比如进入一个程序所在的目录,并以特定的配置执行该程序。

是的,它被称为 alias:

A Bash alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence. If, for example, we include alias lm="ls -l | more" in the ~/.bashrc file, then each lm [1] typed at the command-line will automatically be replaced by a ls -l | more. This can save a great deal of typing at the command-line and avoid having to remember complex combinations of commands and options. Setting alias rm="rm -i" (interactive mode delete) may save a good deal of grief, since it can prevent inadvertently deleting important files.

所以基本上:

alias foo="cd /path/to/dir; ./myprogram; cd -"

cd - 遵循@Cyrus 的建议 - return 将您转到您开始的目录。这对大多数命令来说更安全,更令人期待,但是当然,您可以使用任何您喜欢的方式。