Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As question title stand for <code>system</code> command, this will answer directly, but the sample command using bash contain only thing that will be simplier in perl only (take a look at other answer using <code>opendir</code> and <code>-d</code> in perl).</p> <p>If you want to use <code>system</code> (instead of <code>open $cmdHandle,"bash -c ... |"</code>), the prefered syntax for execution commands like <code>system</code> or <code>exec</code>, is to let <code>perl</code> parsing the command line.</p> <p>Try this (as you've already done):</p> <pre><code>perl -e 'system("bash -c \"echo hello world\"")' hello world perl -e 'system "bash -c \"echo hello world\"";' hello world </code></pre> <p>And now better, same but letting <code>perl</code> ensure command line parsing, try this:</p> <pre><code>perl -e 'system "bash","-c","echo hello world";' hello world </code></pre> <p>There are clearly 3 argument of <code>system</code> command:</p> <ol> <li>bash</li> <li>-c</li> <li>the script</li> </ol> <p>or little more:</p> <pre><code>perl -e 'system "bash","-c","echo hello world;date +\"Now it is %T\";";' hello world Now it is 11:43:44 </code></pre> <p>as you can see in last purpose, there is no double <em>double-quotes</em> enclosing <em>bash script</em> part of command line.</p> <p>**Nota: on command line, using <code>perl -e '...'</code> or <code>perl -e "..."</code>, it's a little heavy to play with quotes and double-quotes. In a script, you could mix them:</p> <pre><code>system 'bash','-c','for ((i=10;i--;));do printf "Number: %2d\n" $i;done'; </code></pre> <p>or even:</p> <pre><code>system 'bash','-c','for ((i=10;i--;));do'."\n". 'printf "Number: %2d\n" $i'."\n". 'done'; </code></pre> <p>Using dots <code>.</code> for <em>concatening</em> part of (script part) string, there are always 3 arguments.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload