3

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?

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Note that the keyword function is not needed and not portable. Simply omit it to work in any Bourne shell.
Thanks. Added a note about that.
"omit it to work in any Bourne shell" as long as you don't use any other bashism in the function, so that you are faced with the usual choice between legacy support and spiffy features of the newest, specialest version.
5

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 Comments

Is it permanent? What if i reboot my machine? (or) Is there a setting/config file storing for that alias commands?
@4lvin yes. In Mac OSX, you can put it into ~/.bash_profile; in Ubuntu or other linux systems, you can put it into ~/.bashrc.
1

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

alias abc='echo "testing"'

2 Comments

Is it permanent? What if i reboot my machine? (or) Is there a setting/config file storing for that alias commands?
Its not permanent. As you reboot it will go away. To overcome this you can this alias in .bashrc (in your home directory)
1

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

3 Comments

Is it permanent? What if i reboot my machine? (or) Is there a setting/config file storing for that alias commands?
@4lvin: Put it in your ~/.bashrc or equivalent.
add it in either .login file or .bashrc file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.