Redirect debug output of bash script to file

Revision history
Tags: bash debugging linux thunar

I needed a way to debug my thunar (file manager) custom actions, as it doesn’t have a way of debugging these scripts itself. I make my thunar Custom actions run a script that contains the following snippet at the top:

#!/bin/bash
logfile=~/tmp/bash-$$.log
exec > $logfile 2>&1
set -x

Where all debug output of set -x will go into $logfile. Great for making sure the supplied command arguments are sent from thunar as expected, which is why most of my custom actions didn’t work before.

References

If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.