4 ms·
A lot of people suggests python, I'd argue that python is a bad fit for what many bash scripts does. A bash script is basically scripting what you do on your t
by tjoff 2y ago
A lot of people suggests python, I'd argue that python is a bad fit for what many bash scripts does.
A bash script is basically scripting what you do on your terminal. I feel like scripting in the same language that is your terminal interface is underrated.
You can basically take a look at your command history and wrap it up as a script.
Yes, bash is clunky as hell. It has some really ugly warts. But learning the basics will make you more proficient in the terminal. The synergies are really nice.
- _xiaz 2y agoAs a linux admin, bash and python are my bread and butter. I have two heuristics for choosing between them: - If it needs more math than counting, choose Python - If it's >200 lines (500 if I'm brave), choose Python Otherwise, shell scripting is nice
- rcxdude 2y agomy heuristic is "if there's an if statement, loop, or variable substitution with uncontrolled input, use python".
- lloeki 2y agoInteresting that a lot of the (general, not specifically here) commentary is "don't use bash, use python" which I find quite clunky, noisy, and boilerplatey to do the same thing as a shell script. Kinda Master Foo and the Ten Thousand Lines†. Ruby's https://github.com/ruby/shell https://github.com/ruby/shell (which used to be bundled in Ruby itself) doesn't get much mention but is much more clear and useful to me. # system commands are not defined by default, only builtins, for safety Shell.def_system_command 'ls' Shell.def_system_command 'grep' Shell.def_system_command 'jq' Shell.new.transact do # simple redirs just work ls | grep('test') > 'some/file' ls | grep('other') | tee('foo') >> 'some/file' # pops at the end of the block cd 'some/dir' do # nested redir for demo (cat < 'foo.json') | jq '.[] | { bar: .bar }' end end † http://www.catb.org/esr/writings/unix-koans/ten-thousand.html http://www.catb.org/esr/writings/unix-koans/ten-thousand.htm...
- kmarc 2y agoSimilar as plumbum for python https://pypi.org/project/plumbum/ https://pypi.org/project/plumbum/ (also supports dispatching commands to SSH sessions)
- lloeki 2y agoplumbum is nice, although the optional parens of Ruby makes things more shellish. Also Ruby's Shell was part of the stdlib, so if a system had Ruby you could use it without having to go through system ruby `gem install` conundrums. I think they made a mistake unbundling that one.
- csomar 2y agoIt’s also something that LLMs generate really well. So you can build reasonably complex scripts with little knowledge of bash.
- j0hnyl 2y agoThis holds for most scripting options.
- d0mine 2y agoYou could use both Bash and Python for tasks they are good at: concisely creating one-line shell pipelines in Bash and implementing complex logic that glues together these pipelines in Python. Example: pyinvoke/fabric https://www.fabfile.org https://www.fabfile.org