3 ms·
> The moral of the story? Same as always: quote, quote quote. Even when things appear to work. I would like to propose a different moral of the story, which i
by AndyKelley 10y ago
> The moral of the story? Same as always: quote, quote quote. Even when things appear to work.
I would like to propose a different moral of the story, which is, as soon as your shell script requires control flow beyond executing a series of commands one after another, switch to a better programming language, such as Python.
- woah 10y agoShell still has a huge advantage over other scripting languages- the syntax to invoke other programs is completely first class and natural. In real programming languages it's always some .os.exec() or whatever. Is python different?
- fnj 10y agoXonsh (a terrific python-based shell) addresses this with great elegance.
- AndyKelley 10y agosubprocess.check_call and subprocess.check_output are far less error-prone than the first class natural syntax of sh, where you have to remember to quote everything or have hidden bugs, likely even security vulnerabilities. And god forbid your coworker has to try to understand your sh code. Clear syntax is better than pretty syntax.
- ams6110 10y agoUse the proper tool for the job, that I agree with. For most sysadmin tasks, that is shell scripts. Yes you have to be aware of the warts, as with any language or framework. I would no more want to do system administration with Python than I would want to write a web application server in bash.
- idobai 10y agoPython maybe better but there are FAR better languages out there...