2

I have a script.py that I'd like to run when the user types "script" in unix. How do I accomplish this, instead of forcing him to type ./script.py each time?

2 Answers 2

3

You need to put the directory of the script in your PATH environment variable.

e.g.

/path/to/script.py
export PATH=$PATH:/path/to

To obviate typing the extension create a local symlink

ln -s /path/to/script.py /path/to/script

This prevents polluting /usr/local/bin with manual symlinks (which could be important on a multi-user) system.

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

1 Comment

That doesn't take care of the extension.
3

You will need to add a symlink to the script, without using the .py extension, and place it somewhere on your system path. For instance, you might do

sudo ln -s myscript.py /usr/local/bin/myscript

Then you will need neither the .py nor the ./.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.