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.

In Linux I always cd to a longish path and then run the script:

cd /scratch/someDir/someOthernestedDir/
./shellscriptName.sh 

How can I avoid achieve typing this longish path and then executing the command with a single step?

Some thing like the below from any path should do what I want:

executeMyCommand

P.S: I am using C-shell.

[subhrcho@slc04lyo bin]$ echo $0
csh
share|improve this question

2 Answers 2

up vote 4 down vote accepted

There are three main ways of running your script without needing to specify the full path.

  1. Add the directory containing your script to your $PATH. You will then be able to execute the script by name from any directory, just like any other program. If you are using csh, add this to your ~/.cshrc:

    set path = ($path /scratch/someDir/someOthernestedDir/)
    
  2. Place a link to your script in a directory that is already in your path. For example /usr/bin:

    ln -s /scratch/someDir/someOthernestedDir/shellscriptName.sh /usr/bin
    
  3. Make an alias as @EightBitTony suggested, add this line to your ~/.cshrc:

    alias executeMyCommand '/scratch/someDir/someOthernestedDir/shellscriptName.sh' 
    
share|improve this answer

Command aliases.

alias name definition

e.g.

alias executeMyCommand '/scratch/someDir/someOthernestedDir/shellscriptName.sh'

From here.

Adding a command alias

To make a command alias a permanent part of your working environment:

  1. Edit the shell startup file .cshrc and add the line defining the alias.
  2. Save the changes and leave the editor.
  3. Source the shell startup file to have the changes take immediate effect. For example:

    source .cshrc

share|improve this answer
    
Why do we need to do the last step. What does source do ? –  Geek Jul 31 '13 at 14:51
1  
@Geek source just tells your shell to read the .cshrc file again. Otherwise, your current shell will not see the new alias and it will only work once you open a new terminal. –  terdon Jul 31 '13 at 15:56

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.