3

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

像:

$ abc
The quick brown fox jumps over the lazy dog.
  • 如何在Linux中简单地制作它?
4

4 回答 4

7

您还应该考虑学习bash 函数,这样您就可以

 function abc () {
   echo The quick brown fox jumps over the lazy dog.
 }

正如其他人告诉你的那样,你也可以使用 bashalias内置。

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

bash 中函数的主要优点是它们可以接受一些参数并且比alias给你的更复杂。

于 2012-12-17T06:19:26.383 回答
5

试试别名

alias abc="echo The quick brown fox jumps over the lazy dog."

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

于 2012-12-17T06:12:21.587 回答
1

alias abc='echo The quick brown fox jumps over the lazy dog.'

于 2012-12-17T06:10:41.510 回答
1

如果我正确理解了您的要求,您可以为此使用别名命令

alias abc='echo "testing"'
于 2012-12-17T06:11:38.093 回答