<p>I am making a bash script to copy files from a Kubernetes pod running Debian. When I include the following line:</p>
<pre><code>kubectl --namespace &quot;$namesp&quot; exec &quot;$pod&quot; -c &quot;$container&quot; -- cd /var
</code></pre>
<p>it errors out:</p>
<pre><code>OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: &quot;cd&quot;: executable file not found in $PATH: unknown
command terminated with exit code 126
</code></pre>
<p>I also tried</p>
<pre><code>kubectl --namespace &quot;$namesp&quot; exec &quot;$pod&quot; -c &quot;$container&quot; -- builtin
kubectl --namespace &quot;$namesp&quot; exec &quot;$pod&quot; -c &quot;$container&quot; -it -- cd /var
</code></pre>
<p>which gave the same result.</p>
<p>I was able to resolve the issue by changing the command to:</p>
<pre><code>kubectl --namespace &quot;$namesp&quot; exec &quot;$pod&quot; -c &quot;$container&quot; -- /bin/bash -c &quot;builtin&quot;
</code></pre>
<p>Would love to understand why the first command(s) don't work and the latter one does. I would have thought that builtin commands are the one group of commands that <em>would</em> always be found, in contrast to commands that rely on the PATH environment variable.</p>

We'll See
<p><code>kubectl exec</code> is used to execute an executable in a running container. The command has to be built into the container.</p>
<p>Neither <code>builtin</code> nor <code>cd</code> are valid executables in your container. Only <code>/bin/bash</code> is.</p>
<p>To execute a builtin shell command, you have to execute the shell and call it as the command argument like in your third example.</p>
