title: Segmentation fault while running MPI program with bash script
body: <p>I'm trying to write a simple script that will test my MPI application with different number of processes. 
  Content of run.sh script:</p>
  
  <pre><code>#!/bin/bash
  if [ $# -lt 3 ]; then
      echo "args required: &lt;thread_count&gt; &lt;executable&gt; &lt;args&gt;..."
      exit
  fi
  
  echo "
  $@
  $(date)"&gt;&gt;result
  
  TH_MAX=$1
  THREAD=2
  while [ $THREAD -le $TH_MAX ]; do
      echo $THREAD threads
      output=$(mpirun -np $THREAD ./$2 $THREAD ${@:3})
      echo $THREAD $output &gt;&gt; result
      let THREAD=THREAD+1
  done
  </code></pre>
  
  <p>Now, when I was using it to run normal programs, everything was great. However, since I call mpirun I get segmentation fault.</p>
  
  <p>Call:</p>
  
  <pre><code>./run.sh 2 main data_file 100
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>2 threads
  [ubuntu:07144] *** Process received signal ***
  [ubuntu:07144] Signal: Segmentation fault (11)
  [ubuntu:07144] Signal code: Address not mapped (1)
  [ubuntu:07144] Failing at address: (nil)
  [ubuntu:07144] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0) [0x7fc6359fccb0]
  [ubuntu:07144] [ 1] /lib/x86_64-linux-gnu/libc.so.6(fgets+0x1e) [0x7fc63569bfee]
  [ubuntu:07144] [ 2] main(main+0x1f7) [0x400f6b]
  [ubuntu:07144] [ 3] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7fc63564e76d]
  [ubuntu:07144] [ 4] main() [0x400cb9]
  [ubuntu:07144] *** End of error message ***
  </code></pre>
  
  <p>I should mention that everything works perfectly when I call mpirun outside of script.</p>