Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Please advice how to do the following magic ( I have linux red-hat machine – 5.4 )

I created the script in the following path:

        /usr/cti/my_scripts/MAGIC.bash

I want to run this script from evry dir in my linux by alias name – M

For example

Under /tmp or /usr/or /var or evry dir When I type M , then it will run the script /usr/cti/my_scripts/MAGIC.bash

Please advice what the steps that need to configure in my linux machine?

EXAMPLE

under /usr

when I enter - M

then it will run the script - /usr/cti/my_scripts/MAGIC.bash

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Edit your "~/.bashrc" or "~/.bash_profile" to include the alias command.

Add this line to your profile:

alias M="/usr/cti/my_scripts/MAGIC.bash"
share|improve this answer

You could use an alias in .bashrc.
But that works only from interactive shells, not in shell scripts.

To make it work in scripts too, you can make a symlink in a directory that is in PATH, for example in $HOME/bin directory. (Create it if missing, could be that it is included into PATH automatically on next login.)

cd ~/bin
ln -s /path/to/M-script.sh M
share|improve this answer

If you have ruby installed, use aka to create permanent alias on the fly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.