<p>I cannot say this is a the best answer so I do hope someone can provide a better clarification.  </p>

<p>It seems the default shell for <code>sh()</code> in Jenkins is Bourne.  By updating the <code>sh()</code> with the correct shell this allows the below usage:</p>

<pre><code>sh'''#!/bin/bash
    IFS='/'
    branch=($1)
    # Use it.
'''
</code></pre>

<p>This doesn't resolve the the redirection error.  Also I would think by updating the default shell in the image with <code>chsh -s /bin/bash</code> I wouldn't need to set it but I still do.</p>

CC BY-SA 4.0
2019-01-15T07:19:33.470Z
2019-01-15T07:33:59.940Z
2019-01-15T07:33:59.940Z
Brandon Clark
<p>Why might the below bash commands give me an error on a Jenkins JNLP slave in Kubernetes cluster? Each work on a local machine.</p>

<hr>

<p><strong>Error:</strong> <code>Syntax error: redirection unexpected</code> </p>

<pre><code>IFS='/' read -r -a branch &lt;&lt;&lt; "${1}"
</code></pre>

<hr>

<p><strong>Error:</strong> <code>Syntax error: "(" unexpected (expecting "}")</code>:  </p>

<pre><code>IFS='/'
branch=($1)
</code></pre>

<hr>

<h1>Environment Details</h1>

<ul>
<li>JNLP Slave is using Dockerhub <a href="https://hub.docker.com/r/jenkins/jnlp-slave/dockerfile" rel="nofollow noreferrer">jenkins/jnlp-slave:latest</a></li>
<li>Slave being ran with <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="nofollow noreferrer">kubernetes plugin</a></li>
<li>Jenkins v2.156 on master.</li>
<li>Command is from a sourced function in another script. (e.g. <code>. "/script.bash"</code>)</li>
</ul>

<jenkins><shell-script><bash>
Bash Tokenization Errors on Jenkins JNLP Slave
Brandon Clark
# Bash Tokenization Errors on Jenkins JNLP Slave

(Asked by: username_0 on 2019-01-14)

Why might the below bash commands give me an error on a Jenkins JNLP slave in Kubernetes cluster? Each work on a local machine.

Error: Syntax error: redirection unexpected 
IFS='/' read -r -a branch <<< "${1}"


Error: Syntax error: "(" unexpected (expecting "}"):  
IFS='/'
branch=($1)


Environment Details

JNLP Slave is using Dockerhub jenkins/jnlp-slave:latest
Slave being ran with kubernetes plugin
Jenkins v2.156 on master.
Command is from a sourced function in another script. (e.g. . "/script.bash")

**Tags:** jenkins, shell-script, bash


---

## 1 answers

### Answer by username_0 on 2019-01-15. Score: 1

I cannot say this is a the best answer so I do hope someone can provide a better clarification.  
It seems the default shell for sh() in Jenkins is Bourne.  By updating the sh() with the correct shell this allows the below usage:
sh'''#!/bin/bash
    IFS='/'
    branch=($1)
    # Use it.
'''

This doesn't resolve the the redirection error.  Also I would think by updating the default shell in the image with chsh -s /bin/bash I wouldn't need to set it but I still do.


---

