Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So I'm here thinking how to create custom commands on my Linux Debian? I mean so I could open up terminal and just type the script name (and possibly some arguments) and it would refer to the script in my home directory. Otherwise I've write the whole path to the script each time and it gets annoying.

share|improve this question
    
This can be done by setting up Aliases. –  paradd0x Apr 29 '11 at 19:44
    
What shell are you using? –  Adam Prax Apr 29 '11 at 19:47
    
I guess it's bash. –  Richards Apr 29 '11 at 19:50

2 Answers 2

up vote 4 down vote accepted

You have to add the path of your scripts to PATH, just put in your ~/.bashrc:

PATH=$PATH:<script-directory-here>

where <script-directory-here> is something like /home/you/scripts/.

share|improve this answer
    
... and add "export PATH" on the next line. –  CarlF Apr 29 '11 at 19:56
    
Thanks guyz, works perfect! –  Richards Apr 29 '11 at 19:59
3  
@CarlF: I never understood the usefulness of export in .bashrc. If you mind a little piece of explanation... –  cYrus Apr 29 '11 at 20:08
    
you could also add a bash alias .. ~/.bash_aliases –  farinspace Jul 18 '12 at 20:30
    
@CarlF You don't need to export it, it's (very likely) already marked as exported. –  gniourf_gniourf Oct 31 '13 at 17:38

Putting your scripts in their own directory, e.g., ~/bin, as cYrus answered, is probably the best solution. Another way to avoid having to "write the whole path to the script each time", though, is to use shortcuts to refer to certain directories. For example, executing

./yourscript

will execute a script named yourscript in the current directory, and

~/yourscript

will execute a script in your HOME directory.

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.