Run your own scripts from any directory when using terminal

We all know that scripts are a very handy way to get repetitive jobs done quicker (and much more).

Now, let’s suppose you have a script located at /path/to/dir directory.
Each time you need to run the script you would:

  1. Open a terminal
  2. change dir to /path/to/dir and then
  3. run your script using “./myscript” notation
  4. Or (a “faster” alternative) writing “/path/to/dir/myscript” to execute it

It might doesn’t look that much to do, but when you’re using it frequently, it can save time to just open a terminal and type “myscript” to run it.

So, in order to do that, you will need to:

  1. create a directory in which your scripts will be saved, i.e. ~/myscripts/
  2. open the file ~/.bashrc in a text editor and append this line:

    or if you choose your directory of scripts to be anywhere else:

  3. As a final step you will need to source your ~/.bashrc or logout/login. To source your bashrc file type:

So, now if you have a script called remote you can open the terminal and just type “remote” and watch the magic happen! 😛

Leave a Comment

Your email address will not be published. Required fields are marked *