3 ms·
I've seen five line bash scripts replaced with thousand line python programs. In an extreme case a pipeline typed directly into slack was productized over weeks
by JonChesterfield 5y ago
I've seen five line bash scripts replaced with thousand line python programs. In an extreme case a pipeline typed directly into slack was productized over weeks into some hundreds of lines of python that did the same thing. I'm going to keep using bash for trivial things.
- hedora 5y agoI routinely replace such 1000 line Python scripts with five lines of bash. Usually, it's in the middle of some production incident, and the script is written for Python that's too new / old for the production machine, or pip does what pip does, or whatever. Protip: These monstrosities usually end up accidentally invoking bash at the bottom, so just copy paste what it would pass to bash and reimplement the argv parsing.
- digisign 5y agoAnd I've replaced several lines of unreadable, dangerous bash (see article) with a Python expression. Especially anything with string-manipulation, which is typically an atrocity in shell or batch languages. Shall we go on?
- QuikAccount 5y agoThat's irrelevant though. The above posters aren't saying "stop using Python." They are defending the use of shell scripts. Both are tools and both have appropriate times where they should be used.
- digisign 5y agoThere should be, could be, possibly are safer shells which would be appropriate. Not bash in its present form, for non-trivial problems.
- lostmsu 5y agoI bet you most bash scripts that don't operate on fixed file names have security vulnerabilities.
- hedora 5y agoMost bash scripts aren't setuid root, so this is mostly a moot point.
- JonChesterfield 5y agoNone are, afaik. Linux flatly refused to let me elevate a script to run with root permissions. I ended up porting said script to c++ just so I could have ./gpu_recover work from a test suite which I'm not going to run as root or type passwords into.
- lostmsu 5y agoI don't think local privilege escalation worth worrying in most cases. It is remote code execution that you should beware. A .ZIP archive containing files with funny file names can go a long way in achieving RCE when handled by a shell script without proper input sanitation (which is exactly what I was referring to).