0

I have just written a python script to do some batch file operations. I was wondering how i could keep it in some common path like rest of the command line utilities like cd, ls, grep etc.

What i expect is something like this to be done from any directory -

$ script.py arg1 arg2

Arun Abraham
  • 4,011
  • 14
  • 54
  • 75

3 Answers3

1

Just put the script directory into the PATH environment variable, or alternatively put the script in a location that is already in the PATH. On Unix systems, you usually use /home/<nick>/bin for your own scripts and add that to the PATH.

poke
  • 369,085
  • 72
  • 557
  • 602
0

Add the directory it is stored in to your PATH variable? From your prompt, I'm guessing you're using an sh-like shell and from your tags, I'm further assuming OS X. Go into your .bashrc and make the necessary changes.

hd1
  • 33,938
  • 5
  • 80
  • 91
0

An alternative approach is to create a python package with entry points and install the program, rather than changing $PATH (using setuptools in setup.py). This has some advantages:

  • Works outside of shells
  • Reduces the amount of system-wide configuration, or at least puts it all in side the package.

See Explain Python entry points? and python: simple example for a python egg with a one-file source file? for details.

This has the advantage of keeping all your settings in one place.

You can use the --develop option so that you can still edit your code in place and the --user option to avoid messing python for other users.

Community
  • 1
  • 1
Att Righ
  • 1,439
  • 1
  • 16
  • 29