Q:

Made quick script to search bash history - How can I make it more robust?

I got tired of typing 
grep "{search term}" ~/.bash_history

to search terms in my previous bash history. so i just wrote out this python script and put it in /usr/bin/local so I only have to type
hist {search term}

And I get a list of all lines in the bash history that used that search term. 
Here's the script:
#hist
#!/usr/bin/python

import subprocess
import sys

subprocess.call("grep " + sys.argv[1] + " ~/.bash_history", shell=True)

It works great for the most part. However I noticed that if I type
hist "-L"

I get the below errors:
File "/usr/local/bin/hist", line 6, in <module>
subprocess.call("grep " + sys.argv[1] + " ~/.bash_history", shell=True)
  File "/usr/lib/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 1392, in wait
pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
return func(*args)

How can I fix this aspect, and what are some best practices for these kinds of scripts in general?

A:

To make a more robust command line program with Python, consider using a library for handling arguments. As of writing this answer, the most popular are Argparse, Docopt, and Click. They all have their own flavor, and it's up to you and your use-case which one is the best fit.
This article does a fairly good comparison of the basic usage of all three.

