1

How to make a programme executable in the SHELL

I have git cloned a number of tools into my HOME folder. Now as there are many of them and my query files are located on a different directory, what I need is make a programme executable from everywhere in the SHELL. I have read this thread but how about Perl and Python scipts. For example, I have a script.pl or script.py file in a folder named scrips. What should I do to make that script run from everywhere?

4 Answers 4

11
  1. Make the scripts executable: chmod +x $HOME/scrips/* This needs to be done only once.
  2. Add the directory containing the scripts to the PATH variable: export PATH=$HOME/scrips/:$PATH (Verify the result with echo $PATH.) The export command needs to be run in every shell session. For convenience, you want to add that command to the $HOME/.profile file so it is run automatically for you at log-in time.

Now you can execute script.pl some-arguments or script.py some-arguments from anywhere.

Sign up to request clarification or add additional context in comments.

Comments

4

just type just type export PATH=$PATH:</path/to/file> then: source ~/.bashrc at the command line it will only last for the length of the session.

If you want to change it permanently add export PATH=$PATH:</path/to/file> to your ~/.bashrc file . follow this link for more explanation https://unix.stackexchange.com/a/3820/401010

1 Comment

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
3

The first thing that comes to mind is using Aliases.

So, there should be nothing preventing you from doing e.g.

$ alias mycoolscript="python /$HOME/scripts/script.py" 

Then you could use it like any other shell command:

$ mycoolscript https://outlick.com/ 

And this would call your Python program.

You can read more about them here

NOTE: The alias wont persist across shell sessions. If you want to add these permanently you can add the alias command to your .bashrc

open $HOME/.bashrc with your favorite text editor and add the line to the bottom

when you are done type

$ source $HOME/.bashrc 

and you can start using the commands

Comments

3

The quickest way is to add your script's directory to the PATH environment variable. Here is an article that describes what the PATH variable is.

  1. Make the script executable by running chmod +x <script-name>
  2. Navigate to the the directory where the script is located and run this command to add the directory consisting your scripts to the PATH echo export PATH=$(pwd):$PATH >> ~/.bashrc && source ~/.bashrc If you are ushing bash as your shell.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.