Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-15T07:19:33.470Z
Answers: 2019-01-15T07:33:59.940Z
Answers: 2019-01-15T07:33:59.940Z
Answers: Brandon Clark
Body: <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>
  
Tags: <jenkins><shell-script><bash>
Title: Bash Tokenization Errors on Jenkins JNLP Slave
UserDisplayName: Brandon Clark
ThreadText: # 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](https://hub.docker.com/r/jenkins/jnlp-slave/dockerfile)
  * Slave being ran with [kubernetes plugin](https://github.com/jenkinsci/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.
  
  
  ---
  
  