Does "set -euo pipefail" have an effect on eval?
<p>Consider the following bash code:
</p>

<pre><code>#!/usr/bin/env bash

set -euo pipefail

Test() {      
  grep 'XXX' data
  echo 'test message'
}
</code></pre>

<p><code>data</code> is an empty file existing in the same directory as the above bash script.</p>

<p>If <code>Test</code> function is invoked with the following code, it produces nothing to stdout. </p>

<pre><code>Test
</code></pre>

<p>The reason is that grep command return exit status <code>1</code> since <code>data</code> does not contains <code>XXX</code>. So <code>set -euo pipefail</code> causes the bash script to exit immediately.</p>

<p>But if it is invoked with:</p>

<pre class="lang-sh prettyprint-override"><code>output=$(eval 'Test')
echo "output: $output"
</code></pre>

<p>It produes the following message to stdout:</p>

<pre><code>output: test message
</code></pre>

<p>It seems that <code>set -euo pipefail</code> does not have an effect on <code>eval</code>. So grep command does not cause the bash script to exit.</p>