From: Terrel S. <tsh...@tr...> - 2001-04-10 04:23:33
|
Ian Bicking wrote: > Terrel Shumway <tsh...@tr...> wrote: > > Why does this start with "#!/bin/sh" instead of "#!/bin/env python"? > > > > I always wonder why intelligent python programmers write sh scripts. Python is obviously *available*. Then again ... I do use perl once in while. 8-) > > Perhaps part of the reason is that the python script would end up > doing its main action with os.system(), which is like running a shell > script, with all the advantages and disadvantages. Doing things like > redirecting output is not easy in Python (even possible? Without using > os.system()?) That makes it bad as a control language. > I have been contemplating a module shell.py to take care of the I/O redirecting without using os.system (which IS exactly running a shell). Avoiding os.system avoids 200 security holes related to argument quoting and parsing and race conditions while files are opened and closed. 80% of the stuff you do with a shell script requires spawning a tiny program to do what is built in to the language or the standard library in python. Why spawn /bin/kill (50 system calls and a ton of quoting and parsing) when you can just make the call directly with os.kill()? No, it is not that cut and dried, but there are a lot fewer hoops to jump through in python. Maybe it the challenge of doing a lot with little, like writing programs for an 8-bit CPU to run in 4KB of RAM, or writing a mail server in perl. 8-) I have already written pieces of this shell module, but have never put them all together. |