Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to distribute my Python/shell script?

Tags:

python

bash

shell

I have written a very simple command line utility for myself. The setup consists of:

  1. A single .py file containing the application/source.
  2. A single executable (chmod +x) shell script which runs the python script.
  3. A line in my .bash_profile which aliases my command like so: alias cmd='. shellscript' (So it runs in the same terminal context.)

So effectively I can type cmd to run it, and everything works great.

My question is, how can I distribute this to others? Obviously I could just write out these instructions with my code and be done with it, but is there a faster way? I've occasionally seen those one-liners that you paste into your console to install something. How would I do that? I seem to recall them involving curl and piping to sh but I can't remember.

like image 240
hamstu Avatar asked Oct 05 '22 19:10

hamstu


2 Answers

Upload your script to something like ideone. Then tell your friend to pipe it into python. Example script:

def print_message():
    print "This is my very special script!"

if __name__ == "__main__":
    print_message()

Example of running script:

username@server:~$ curl http://ideone.com/plain/O2n3Pg 2>/dev/null | python
This is my very special script!
like image 154
Claudiu Avatar answered Oct 13 '22 11:10

Claudiu


chmod +x cmd.py

then they can type ./cmd.py

they can also use it piped.

I would add that unix users would probably already know how to make a file executable and run it, so all you'd have to do is make the file available to them.

Do make sure they know what version(s) of python they need to run your script.

like image 38
Christopher Mahan Avatar answered Oct 13 '22 11:10

Christopher Mahan