<p>I would like to execute an OS command from my ruby script but I want to add an argument from a ruby variable.</p>

<p>I know that's possible by using keyword <em>system</em> like that :</p>

<pre><code>#!/usr/bin/env ruby
directory = '/home/paulgreg/'
system 'ls ' + directory
</code></pre>

<p>but is that possible by using the "backquotes or backticks syntax" ?
(I mean by using that syntax : <code>ls</code>)</p>

[{'answer_id': 41635, 'author': 'Jordi Bunster', 'author_id': 4272, 'author_profile': 'https://Stackoverflow.com/users/4272', 'pm_score': 4, 'selected': True, 'text': "<p>No, that will just concatenate the output from <code>ls</code> and the contents of <code>directory</code>.</p>\n\n<p>But you can do this:</p>\n\n<pre><code>#!/usr/bin/env ruby\ndirectory = '/home/paulgreg/'\n`ls #{directory}`\n</code></pre>\n"}, {'answer_id': 41892, 'author': 'Nick Brosnahan', 'author_id': 528, 'author_profile': 'https://Stackoverflow.com/users/528', 'pm_score': 3, 'selected': False, 'text': '<pre><code>`ls #{directory}` \n</code></pre>\n\n<p>isn\'t very safe because you\'re going to run into problems with path names that have spaces in them.  </p>\n\n<p>It\'s safer to do something like this:</p>\n\n<pre><code>directory = \'/home/paulgreg/\'\n\nargs = []\nargs &lt;&lt; "/bin/ls"\nargs &lt;&lt; directory\n\nsystem(*args)\n</code></pre>\n'}, {'answer_id': 71636, 'author': '0124816', 'author_id': 11521, 'author_profile': 'https://Stackoverflow.com/users/11521', 'pm_score': 1, 'selected': False, 'text': "<p>Nick is right, but there is no need to assemble the args piecewise:</p>\n\n<pre><code>directory = '/Volumes/Omg a space/'\nsystem('/bin/ls', directory)\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/41630', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3122/']