Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858https://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command then you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility and level to write output via local syslog to its own logfile.

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command then you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility and level to write output via local syslog to its own logfile.

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: https://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command then you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility and level to write output via local syslog to its own logfile.

added 4 characters in body
Source Link
Cyrus
  • 12.8k
  • 3
  • 32
  • 55

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command then you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility.level pair and level to write output via local syslog to its own logfile.

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility.level pair to write output via local syslog to its own logfile.

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command then you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility and level to write output via local syslog to its own logfile.

added 20 characters in body
Source Link
Cyrus
  • 12.8k
  • 3
  • 32
  • 55

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility.level pair to write output via local syslog to its own logfile.

Start your bash script with bash -x ./script.sh or add in your script set -x.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility.level pair to write output via local syslog to its own logfile.

Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.


Additional with bash 4.1 or later:

If you want to write the debug output to a separate file, add this to your script:

exec 5> debug_output.txt BASH_XTRACEFD="5" 

See: http://stackoverflow.com/a/25593226/3776858


If you want to see line numbers add this:

PS4='$LINENO: ' 

If you have access to `logger` command you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here 

You can use option -p of logger command to set an individual facility.level pair to write output via local syslog to its own logfile.

+logger
Source Link
Cyrus
  • 12.8k
  • 3
  • 32
  • 55
Loading
PS4 added
Source Link
Cyrus
  • 12.8k
  • 3
  • 32
  • 55
Loading
added 243 characters in body
Source Link
Cyrus
  • 12.8k
  • 3
  • 32
  • 55
Loading
Source Link
Cyrus
  • 12.8k
  • 3
  • 32
  • 55
Loading