How to distribute code to be executed by an external command? Bash script?
<p>EDIT: Based on discussions below, I think my question really code apply to any language. Python naturally has a packaging system and installation procedure via <code>pip</code>. But let's say this was C code or a perl script. Users still would download the program files, and have a way to execute the code in the command line via <code>capsall input.txt</code>. </p>

<p>I have a python script that takes an input file and gives an output file.</p>

<p>For a concrete example, this script <code>file1.py</code> takes in an input text file and outputs a text file with all letters capitalized:</p>

<pre><code>import sys
inFile = sys.argv[1]
outFile = sys.argv[2]

with open(inFile,'r') as input_file:
    lines = input_file.readlines()

# process the input file somehow
# here we simply capitalize the text, 
# but naturally something more complex is possible

capitalized_lines = []
for line in lines:
    capitalized_lines.append(line.upper())

with open(outFile,'w') as output_file:
    for line in capitalized_lines:
        output_file.write(line)
</code></pre>

<p>The way users execute this code now with </p>

<pre><code>python file1.py input.txt output.txt
</code></pre>

<p>Let's say I wanted to distribute this code such that users would download a tarball and be able to execute the above in the command line with (for example)</p>

<pre><code>capsall input.txt
</code></pre>

<p>which would run <code>python file1.py</code> and output the file <code>output.txt</code>. Does one write a bash script? If so, how do you distribute the code such that users will have this in their PATH? </p>

<p>Add a "hash bang" at the top of the script file to tell bash to invoke the Python interpreter. Also make your script executable:</p>

<pre><code>#!/usr/bin/env python
import sys

inFile = sys.argv[1]
outFile = sys.argv[2]
...
</code></pre>

<p>Make the script file executable:</p>

<pre><code>$ cp file1.py capsall
$ chmod +x capsall
</code></pre>

<p>Now you can run the script with:</p>

<pre><code>$ ./capsall input.txt output.txt
</code></pre>

<p>Or if <code>capsall</code> is on your path:</p>

<pre><code>$ capsall input.txt output.txt
</code></pre>

python bash shell unix command