title: bash script to perform action in a singularity container it opens
body: <p>I am using the following workflow on RedHat in terminal:</p>
  
  <ul>
  <li>open a singularity image:</li>
  </ul>
  
  <p><code>singularity run /mn/sarpanitu/singularity/test/fenics-and-more.img
  </code></p>
  
  <ul>
  <li>export some display inside the singularity:</li>
  </ul>
  
  <p><code>export DISPLAY=:0.0
  </code></p>
  
  <ul>
  <li>export a path to <em>gmsh</em> inside the singularity:</li>
  </ul>
  
  <p><code>export PATH="$HOME/Downloads/gmsh-git-Linux64/bin:$PATH"
  </code></p>
  
  <p>I want to put everything as a bash script. My first (not working) approach is the following (all in a <em>singularity_script.sh</em> file):</p>
  
  <pre><code>#!/bin/bash
  
  function singularity_script(){
    singularity run /mn/sarpanitu/singularity/test/fenics-and-more.img
    export DISPLAY=:0.0
    export PATH="$HOME/Downloads/gmsh-git-Linux64/bin:$PATH"
  }
  </code></pre>
  
  <p>I execute it by sourcing and then calling the function:</p>
  
  <pre><code>chmod +x singularity_script.sh
  . singularity_script.sh
  singularity_script
  </code></pre>
  
  <p>But of course, this does not work as the exports are done (I think?) in the parent terminal and not the son singularity. So I do not get the display and path exported correctly in singularity.</p>
  
  <p>Any way to fix this? I guess the solution would be to automatically run the script inside the container at startup of the container, but how to do this simply?</p>