<p>I am trying to run the following command on a pod from my local machine.</p>
<pre><code>kubectl -n myns exec mypod -- /bin/bash -c &quot;err=$(tar -cvzf /tmp/logs_aj.tgz ${all_files} 2&gt;&amp;1) || ( export ret=$?; [[ $err == *&quot;No such file or directory&quot;* ]] || exit &quot;$ret&quot; )&quot;
</code></pre>
<p>The command stores the output of the command in a variable and if the output contains a &quot;No such file or directory&quot; it ignores it else exits with the return code.</p>
<p>The command itself: <code>err=$(tar -cvzf /tmp/bludr-logs_aj.tgz ${all_files} 2&gt;&amp;1) || ( export ret=$?; [[ $err == *&quot;No such file or directory&quot;* ]] || exit &quot;$ret&quot; )</code> runs fine when I run this manually inside the pod. But when I try to run this remotely using exec it gives it won't accept <code>*</code>. Here is what I get:</p>
<pre><code>root:~# kubectl -n myns exec mypod -- /bin/bash -c &quot;err=$(tar -cvzf /tmp/logs_aj.tgz ${all_files} 2&gt;&amp;1) || ( export ret=$?; [[ $err == *&quot;No such file or directory&quot;* ]] || exit &quot;$ret&quot; )&quot;
such: Cowardly: command not found
such: -c: line 1: conditional binary operator expected
such: -c: line 1: syntax error near `*No'
such: -c: line 1: `Try 'tar --help' or 'tar --usage' for more information. || ( export ret=2; [[  == *No'
command terminated with exit code 1
</code></pre>
<p>I tried to replace * with <code>&amp;2A</code> but that did not work.</p>

codec
<p>Your command contain nested double quotes so use single quotes instead:</p>
<pre><code>kubectl -n myns exec mypod -- /bin/bash -c 'err=$(tar -cvzf /tmp/logs_aj.tgz ${all_files} 2&gt;&amp;1) || ( export ret=$?; [[ $err == *&quot;No such file or directory&quot;* ]] || exit &quot;$ret&quot; )'
</code></pre>
