Monday, March 8, 2010

Backticks and Ruby Shell Scripting by Yar

Here are my additional notes on Ruby shell scripting from here.

  1. Backticks (or back-ticks) let you do some scripting stuff a lot easier. Consider

     puts `find . | grep -i lib`
  2. If you run into problems with getting the output of backticks, the stuff is going to standard err instead of standard out. Use this advice

     out = `git status 2>`
  3. Backticks do string interpolation:

     blah = 'lib'
    `touch #{blah}`
  4. You can pipe inside Ruby, too. It's a link to my blog, but it links back here so it's okay :) There are probably more advanced things out there on this topic.

  5. As other people noted, if you want to get serious there is Rush: not just as a shell replacement (which is a bit too zany for me) but also as a library for your use in shell scripts and programs.

1 comment:

Daniel Rosenstark said...

I should mention that Rush has no current maintainer, so that makes it less than attractive.

http://groups.google.com/group/ruby-shell/browse_thread/thread/75c8cea757d2f680#