4

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.

  • 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. – Rihards Apr 29 '11 at 19:50
5

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/.

  • ... and add "export PATH" on the next line. – CarlF Apr 29 '11 at 19:56
  • 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
  • 1
    Rather, I would prepend my personal path to the PATH variable, so as to be able to override otherwise existing commands with my own. – gniourf_gniourf Oct 31 '13 at 17:40
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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