▲ | aborsy 3 days ago | |||||||||||||||||||
Isn’t it better to replace bash scripting with Python or similar, unless the script is simple? | ||||||||||||||||||||
▲ | mdaniel 3 days ago | parent | next [-] | |||||||||||||||||||
This trope comes up every time bash is mentioned, without fail. Unless your team enjoys reading this, then no, a general purpose programming language is not a good replacement for what is effectively a "subprocess orchestration language":
The line noise is outrageous as compared to a language built for changing directories and running commandsThat's not even getting into the pty portion, where the progress of the output isn't visible until the end of it, which is terrible DX | ||||||||||||||||||||
| ||||||||||||||||||||
▲ | pragma_x 2 days ago | parent | prev | next [-] | |||||||||||||||||||
IMO, using something like Python or JavaScript is a good idea if any of the following criteria is met: - Working with data more than executing other binaries - Dominant data processing path is structured (e.g. JSON, XML, binary) - Script requires complex flow control to be manageable (e.g. functions, if, case) - Shell UI requirements that involve handling command-line options - You find yourself going _deep_ into the docs for jq to get the job done . Conversely, BASH is better under the following circumstances: - Orchestrating other binaries the majority of the time - Simple jobs that work with newline-separated text lines, or all data can be comfortably "stringly typed" - Launching and job control for other processes - You just need to glue some other shell commands and binaries together - Are just manipulating shell environment vars, or providing a custom user shell (e.g. Python venv `activate`) - Need to wrap a CLI tool in a simple way . The minute you have to reach for BASH arrays, case statements, math... stop everything and seriously consider using a language that has stronger support for all that. | ||||||||||||||||||||
| ||||||||||||||||||||
▲ | 2 days ago | parent | prev | next [-] | |||||||||||||||||||
[deleted] | ||||||||||||||||||||
▲ | m463 2 days ago | parent | prev | next [-] | |||||||||||||||||||
don't listen to the others. yes. I think if you find yourself dropping to sed/grep/awk/find too much, switch to python. The language itself imho seems more readable. Strings, lists and hashes seem better especially when you choke on quoting. And the python standard library makes a huge difference when you grow above "simple". I love argparse for readable arguments with help. os.path lets you manipulate paths and filenames in a readable and robust way. you can read and write json, csv and more. datetime lets you manipulate dates and times. | ||||||||||||||||||||
▲ | dec0dedab0de 3 days ago | parent | prev [-] | |||||||||||||||||||
yes, unless you need it to run somewhere that you know only has bash. |