0

I have a python script, which has multiple command line options. I want to make this script runnable without having to type "python myscript.py" and without having to be in the same directory as the script. For example, if one installs git on linux, regardless of which directory the user is in, the user can do "git add X, etc..". So, an example input I would like is "myscript -o a,b,c -i" instead of "python myscript.py -o a,b,c -i". I already added "#! /usr/bin/env python" to the top of my script's code, which makes it executable when I type "./myscript", however I don't want the ./, and I want this to work from any directory.

1
  • You need to move it somewhere on your path, such as (typically) /usr/bin or /usr/local/bin. This is noted by Then, make the script executable and put it somewhere in your PATH. in the answer to the duplicate. Commented Jul 28, 2014 at 20:30

2 Answers 2

1

You should add the folder that contains the script to your system's $PATH variable (I assume you're on Linux). This variable contains all of the directories that are searched looking for a specific command. You can add to it by typing PATH=/path/to/folder:$PATH. Alternately, you need to move the script into a folder that's already in the $PATH variable (which is generally a better idea than messing with system variables).

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

Comments

0

Your script needs to be in a location searchable via your PATH. On Unix/Linux systems, the generally accepted location for locally-produced programs and scripts that are not part of the system is /usr/local/bin. So, make sure your script is executable by running chmod +x myscript, then move it to the right place with sudo mv myscript /usr/local/bin (while in the directory containing myscript). You'll need to enter an admin's password, then you should be all set.

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.