title: Bash -x or set -x
body: <p>Is there any practical difference in debugging using <code>bash -x scriptname.sh</code> or using <code>set -x</code> inside the script and then calling it?</p>
  <p>In my personal experience I always use <code>bash -x</code> because that way I don't have to change the script so it's less invasive.</p>
  <p>Is there a scenario where <code>bash -x</code> would not fit and just <code>set -x</code> would work?</p>
  <p>I came up with these questions because I always see people suggesting <code>set -x</code> when trying to help others to debug and I was wondering why not <code>bash -x scriptname.sh</code>. Is there a technical limitation?</p>
  <p>PS: I'm not asking about what the commands do, but I'm asking &quot;how&quot; they do and if one is better than the other.</p>
  <p>About what they do:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/10107124/bash-x-command">bash -x command</a></li>
  <li><a href="https://stackoverflow.com/questions/36273665/what-does-set-x-do">What does `set -x` do?</a></li>
  </ul>