4 ms·
For people that know Ruby, if you haven't explored Ruby's CLI abilities, you definitely, definitely should[1][2]. When I was building my (free and open source)
by freedomben 5y ago
For people that know Ruby, if you haven't explored Ruby's CLI abilities, you definitely, definitely should[1][2]. When I was building my (free and open source) awk course[3] I fell in love with awk. When I later found out that Ruby has some of the same features, it changed my life:
[1]: https://robm.me.uk/2013/11/ruby-enp/ https://robm.me.uk/2013/11/ruby-enp/
[2]: https://benoithamelin.tumblr.com/ruby1line/ https://benoithamelin.tumblr.com/ruby1line/
[3]: https://github.com/FreedomBen/awk-hack-the-planet https://github.com/FreedomBen/awk-hack-the-planet
- js2 5y agoPerl too. The -p, -n, -e switches work identically. -n causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed -n or awk: LINE: while (<>) { ... # your program goes here } -p causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed: LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; } https://linux.die.net/man/1/perlrun https://linux.die.net/man/1/perlrun
- p_l 5y agoLittle underappreciated part of Ruby these days is that part of it grew out of Perl, and specifically supports similar kind of scripting for daily tasks. Pretty sure both thsoe specific switches and some of the sigils used in syntax came from this Perl legacy.
- freedomben 5y agoYes thanks, I should have added that perl took it (and improved it) from awk, and ruby took it from perl. Most ruby people don't like to remember that ruby has a lot of perl-isms in it, but I think perl was a great language (and probably is, though I liked ruby so much better I never looked back).
- rcthompson 5y agoMy mnemonic for the perl switches is "perl dash lane", i.e. `perl -lane`. And then I remember to replace "n" with "p" if I want to auto-print every line after munging it. I mainly use this as a replacement for sed/awk/grep because PCRE syntax is more familiar to me than whatever flavor(s) of regexes are used by those tools.
- deleted 5y ago[deleted]
- nomorecommas 5y agoYep, ruby is a natural, pipeline friendly, command line companion out of the box. https://github.com/learnbyexample/Command-line-text-processing/blob/master/ruby_one_liners.md#start-of-content https://github.com/learnbyexample/Command-line-text-processi... https://learnbyexample.github.io/learn_ruby_oneliners/ https://learnbyexample.github.io/learn_ruby_oneliners/
- asicsp 5y agoThanks for the shout out for my Ruby one-liners ebook. The second link (https://learnbyexample.github.io/learn_ruby_oneliners/ https://learnbyexample.github.io/learn_ruby_oneliners/) is the latest version.
- indigodaddy 5y agoDoes ruby come standard on most distros (Eg mainly thinking of RHEL-based here), or you’d have to install it usually?
- asicsp 5y agoDon't know about RHEL and I'm not aware of Linux distros that come with Ruby pre-installed. Perl/Python are usually available by default.
- CopperWing 5y agoSuse/openSuse comes with Ruby pre-installed because Yast, their distinctive system manager tool, is written in Ruby.
- freedomben 5y agoUsually not, although it's one of the top/main packages supported by Red Hat. `dnf install ruby` will work everywhere.