Ruby Backticks - break command into multiple lines?

asfallows picture asfallows · Apr 3, 2012 · Viewed 10.5k times · Source

In Ruby, I know I can execute a shell command with backticks like so:

`ls -l | grep drw-`

However, I'm working on a script which calls for a few fairly long shell commands, and for readability's sake I'd like to be able to break it out onto multiple lines. I'm assuming I can't just throw in a plus sign as with Strings, but I'm curious if there is either a command concatenation technique of some other way to cleanly break a long command string into multiple lines of source code.

Answer

Mark Thomas picture Mark Thomas · Apr 3, 2012

You can escape carriage returns with a \:

`ls -l \
 | grep drw-`