Replacing 'source file' with its content, and expanding variables, in bash
<p>In a script.sh,</p>

<pre><code>source a.sh
source b.sh

CMD1
CMD2
CMD3
</code></pre>

<p>how can I replace the <code>source *.sh</code> with their content (without executing the commands)?
I would like to see what the bash interpreter executes after sourcing the files and expanding all variables.</p>

<p>I know I can use <code>set -n -v</code> or run <code>bash -n -v script.sh 2&gt;output.sh</code>, but that would not replace the source commands (and even less if a.sh or b.sh contain variables).</p>

<p>I thought of using a subshell, but that still doesn't expand the source lines. I tried a combination of <code>set +n +v</code> and <code>set -n -v</code> before and after the source lines, but that still does not work.</p>

<p>I'm going to send that output to a remote machine using ssh.
I could use <code>&lt;&lt;output.sh</code> to pipe the content into the ssh command, but I can't log as root onto the remote machine, but I am however a sudoer.
Therefore, I thought I could create the script and send it as a base64-encoded string (using <a href="https://serverfault.com/questions/625641/how-can-i-run-arbitrarily-complex-command-using-sudo-over-ssh">that clever trick</a> )
<code>base64 script | ssh remotehost 'base64 -d | sudo bash'</code></p>

<p>Is there a solution?
Or do you have a better idea?</p>