Linux to define Custom Shell Command?

2019-05-19 18:07发布

问题:

I want to simply define a custom shell command, for example:
I type abc and it will output some text.

Like:

$ abc
The quick brown fox jumps over the lazy dog.
  • How to make it simply in Linux?

回答1:

Try alias

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

you can add it into your ~/.bash_profile to make it valid for all sessions.



回答2:

You also should consider learning about bash functions so you would have

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

and as others told you, you could also use bash alias builtin.

You may want to remove the bash-specific function keyword to be portable to other Posix shells.

The main advantage of functions in bash is that they can take some arguments and be more complex than what alias give you.



回答3:

If i have understood your requirement correctly ,you can use alias command for this

alias abc='echo "testing"'


回答4:

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



标签: linux shell