io redirection - redirect all output in a bash script when using set -x -


i have bash script has set -x in it. possible redirect debug prints of script , output file? ideally this:

#!/bin/bash set -x (some magic command here...) > /tmp/mylog echo "test" 

and the

+ echo test test 

output in /tmp/mylog, not in stdout.

this i've googled , remember myself using time ago...

use exec redirect both standard output , standard error of commands in script:

#!/bin/bash logfile=$$.log exec > $logfile 2>&1 

for more redirection magic check out advanced bash scripting guide - i/o redirection.

if want see output , debug on terminal in addition in log file, see redirect copy of stdout log file within bash script itself.

if want handle destination of set -x trace output independently of normal stdout , stderr, see bash storing output of set -x log file.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -