Linux定义自定义Shell命令?

夏期劇*_*期劇場 2 linux shell

我想简单地定义一个自定义shell命令,例如:
我输入abc并输出一些文本.

喜欢:

$ abc
The quick brown fox jumps over the lazy dog.
Run Code Online (Sandbox Code Playgroud)
  • 如何在Linux中简单地制作它?

Bas*_*tch 6

你也应该考虑学习bash函数,这样你就可以了

 function abc () {
   echo The quick brown fox jumps over the lazy dog.
 }
Run Code Online (Sandbox Code Playgroud)

而正如其他人告诉你的那样,你也可以使用bash aliasbuiltin.

您可能希望删除特定于bash的function关键字以便移植到其他Posix shell.

bash中函数的主要优点是它们可以采用一些参数并且比alias提供给你的更复杂.


Yua*_*Guo 5

尝试别名

alias abc="echo The quick brown fox jumps over the lazy dog."
Run Code Online (Sandbox Code Playgroud)

您可以将它添加到您的 ~/.bash_profile 中以使其对所有会话都有效。