3 ms·
I'm not sure I'm comfortable with python for a typical shell script. But then again, what alternatives exist? I've been thinking that we are kind of stuck with
by tjoff 7y ago
I'm not sure I'm comfortable with python for a typical shell script. But then again, what alternatives exist?
I've been thinking that we are kind of stuck with it. Much like javascript.
So, we could go the route of typescript and have a translation layer and outputting shell scripts. I actually think that could work quite well from a technical standpoint.
A big part of shellscripts though is having the source available. So maybe even have the translated, original code, and the generated shell output in the same file.
The source code on top (out of view from a shell interpreter) and the generated code below. This would allow it to be readable by anyone and executable by anyone, but modifying it would require the transpiler (which by itself would probably be pretty lightweight as well - certainly compared to python).
Certainly not perfect, but preferable to rediscovering the nuances and gotchas of shell-scripts every other day. Or maybe such a solution would only prolong the suffering and we should start all over.
- Bnshsysjab 7y agoWhat’s wrong with python?
- tjoff 7y agoFeels like the wrong tool for the job with the whole virtual environment that has to be brought up. Performance for shell scripts isn't super critical in my eyes but the startup time of python feels too much for something you might want to run in an inner-loop from find or something. Not sure if python IO performance is suitable for shell scripts either. Also isn't nearly as universal as shell-scripts nor something you necessarily have/want on small systems. But I will admit that I'm channeling prejudices and don't feel I have enough of a complete picture to say anything definite about it. Others in this thread touch upon it though.
- Bnshsysjab 7y agoYou don’t need a virtual env. I probably wouldn’t wrap GNU find and python, I’d just walk the directory tree in python and use regex. IO is suitable for everyday tasks and shouldn’t be an issue in Python anyway, if it is either you’re doing it wrong or your shell script should be written in C and not touch interpreted/bytecode compiled languages at all.
- tjoff 7y agoMe neither, but a big point of shell scripts is that they are the same commands you'd run on the shell itself. And there are lots of really optimized tools that are as quick as can be, throwing them out is a hefty price to pay.
- effie 7y agoIt's too high level for a shell - the unix concepts are too many keystrokes and modules away in python. Also, bad performance.
- ryl00 7y ago> I'm not sure I'm comfortable with python for a typical shell script. But then again, what alternatives exist? perl still exists, and is a wonderful alternative to python for "shell scripts plus". The syntax should be at least vaguely familiar to anyone who has touched bash, awk, sed, etc.
- gbacon 7y agoWhen these threads come up, it’s staggering to see how much mindshare Perl has lost. This particular case of code that grows too klunky for the Unix shell was a key motivator for the language’s invention and ought to be THE final outpost, but people barely seem aware of the option.