From: "WILLS, JAMAL A" Date: 2012-12-15T03:50:39+09:00 Subject: Re: Invoking bash from Ruby There are a number of ways of executing system code from Ruby. As you are familiar with Bash, the easiest would probably be to use a pair of backticks "``" to execute code. Ruby returns the output as a string. date = `grep "Date:" $1 | cut -d' ' -f3-5` You may also use the executable string notation "%x{}" which is similar to Bash's "$()" notation. date = %x{grep "Date:" $1 | cut -d' ' -f3-5} You can check the exit status using "$?" as you would in Bash as well. However, an object is returned so you will want to compare "$?.exitstatus". There are also commands like "system", "exec", "spawn", etc., which make other shell features accessible. Jamal Wills -----Original Message----- From: Paul Mena [mailto:lists@ruby-forum.com] Sent: Friday, December 14, 2012 1:16 PM To: ruby-talk ML Subject: Invoking bash from Ruby I'm a novice at Ruby, although I've been introduced to its syntax by virtue of working with Puppet for the past 2 1/2 years. As a sys admin, I'm most comfortable working with bash, but I recognize that there are things that a scripting language can't do - like interacting with a database. So I'm writing some Ruby code to extract text out of an HTML file and then insert it into a mySQL database. I've been using Nokogiri to get some formatted text, but also need to get some text that's easy enough to get with a scripting language like bash. Specifically, I need to do this: grep "Date:" $1 | cut -d' ' -f3-5 Is there an easy way to embed this logic within Ruby code - or, better yet - a way to do the same thing in Ruby? -- Posted via http://www.ruby-forum.com/.