<p>I am learning kubernetes and have the following question related to command and argument syntax for POD.</p>
<p>Are there any specific syntax that we need to follow to write a shell script kind of code in the arguments of a POD? For example</p>
<p>In the following code, how will I know that the while true need to end with a semicolon ; why there is no semi colon after do but after If etc</p>
<pre><code>   while true;
  do
  echo $i;
  if [ $i -eq 5 ];
  then
    echo &quot;Exiting out&quot;;
    break;
  fi;
      i=$((i+1));
      sleep &quot;1&quot;;
  done
</code></pre>
<p>We don't write shell script in the similar way from semicolon prespective so why do we have to do this in POD.</p>
<p>I tried the command in /bin/bash format as well</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: bash
  name: bash
spec:
  containers:
  - image: nginx
    name: nginx
    args:
    - /bin/bash
    - -c
    - &gt;
       for i in 1 2 3 4 5
       do
         echo &quot;Welcome $i times&quot;
       done
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
</code></pre>
<p>Error with new code</p>
<pre><code>/bin/bash: -c: line 2: syntax error near unexpected token `echo'
/bin/bash: -c: line 2: `  echo &quot;Welcome $i times&quot;'
</code></pre>

James Stan
<p><code>Are there any specific syntax that we need to follow to write a shell script kind of code in the arguments of a POD?</code></p>
<p>No, shell syntax is the same across.</p>
<p><code>...how will I know that the while true need to end with a semicolon</code></p>
<p>Used <code>|</code> for your text block to be treated like an ordinary shell script:</p>
<pre><code>...
args:
- /bin/bash
- -c
- |
  for i in 1 2 3 4 5
  do
    echo &quot;Welcome $i times&quot;
  done
</code></pre>
<p>When you use <code>&gt;</code> your text block is merge into a single line where newline is replaced with white space. Your command become invalid in such case. If you want your command to be a single line, then write them with <code>;</code> like you would in ordinary terminal. This is shell scripting standard and is not K8s specific.</p>
<p>If you must use <code>&gt;</code>, you need to either add empty line or indented the next line correctly:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    run: bash
  name: bash
spec:
  containers:
  - image: nginx
    name: nginx
    args:
    - /bin/bash
    - -c
    - &gt;
      for i in 1 2 3 4 5
        do
          echo &quot;Welcome $i times&quot;
        done
  restartPolicy: Never
</code></pre>
<p><code>kubectl logs bash</code> to see the 5 echos and <code>kubectl delete pod bash</code> to clean-up.</p>
