3 ms·
Interesting 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
by lloeki 2y ago
Interesting 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.