title: Use oc rsh to run for loop in container (openshift remote ssh)?
body: <p>Based on:</p>
  
  <p><a href="https://unix.stackexchange.com/questions/1459/remote-for-loop-over-ssh">https://unix.stackexchange.com/questions/1459/remote-for-loop-over-ssh</a></p>
  
  <p>I am trying to run a for loop command through <code>oc rsh</code> but it fails with below error:</p>
  
  <pre><code>$ oc rsh my-app-10-lprki 'for i in /var/lib/*; do echo $i; done'
  exec failed: container_linux.go:345: starting container process caused "exec: \"for i in /var/lib/*; do echo $i; done\": stat for i in /var/lib/*; do echo $i; done: no such file or directory"
  command terminated with exit code 1
  </code></pre>
  
  <p>I have also tried without quotes, with double quotes but that also fails.</p>
  
  <p>This works fine (without quotes):</p>
  
  <pre><code>$ oc rsh my-app-10-lprki ls -la /var/lib/
  total 24
  drwxr-xr-x.  1 root       root   104 Nov 22 22:21 .
  drwxr-xr-x.  1 root       root    17 Sep 28  2017 ..
  drwxr-xr-x.  2 root       root    44 Sep 28  2017 alternatives
  </code></pre>
  
  <p>Any suggestions on how to run a for loop remotely through <code>oc rsh</code> like (that currently fails):</p>
  
  <pre><code>oc rsh my-app-10-lprki 'for i in /var/lib/*; do echo $i; done'
  </code></pre>
  
  <p>?</p>
  
  <p>Based on below suggestions I have also tried:</p>
  
  <pre><code>$ oc rsh my-app-10-lprki -- /bin/sh  -c  'for i in `ls  /var/lib`; do echo $i; done'
  exec failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH"
  command terminated with exit code 1
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>$ oc rsh my-app-10-lprki -- /bin/bash  -c  'for i in `ls  /var/lib`; do echo $i; done'
  exec failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH"
  command terminated with exit code 1
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>$ oc rsh my-app-10-lprki -- /usr/bin/bash  -c  'for i in `ls  /var/lib`; do echo $i; done'
  exec failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH"
  command terminated with exit code 1
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>$ oc rsh my-app-10-lprki which bash
  /usr/bin/bash
  </code></pre>