better bash debugging
I was trying to debug some bash scripts yesterday and learnt something new π
There are lot of things in bash that you can use to debug and to start with you can enable xtrace mode as follows:
set -x
With this set you will see that all the commands are printed along with all other information as they are executed.
This you can do for any line or for the function or for the whole script. Once you set the option you can turn it
off with
set +x
Now, once you have enabled this, you will see a lot of output, but you will still not see the function name and the line numbers. If you do want to see them then you will need to set the PS4 variable like below and bingo :
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
Related articles
- faster bash operations on files with File Descriptors. (amit-agarwal.co.in)
- bash completion (amit-agarwal.co.in)
- One line Tropo debugging gem (simeonov.com)
Related Articles:
- 2011/08/09 bash completion
- 2011/06/11 faster bash operations on files with File Descriptors.
- 2010/11/20 Broadcast your shell thru port 5000
- 2010/11/09 Print all environment variables, including hidden ones
- 2010/09/24 bash script to run a command and take screenshot in every loop.
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.