How to debug shell script?
Hello everyone,
I am using RedHat Shrike 9.0. I am wondering how to debug shell script, for example, step-by-step debug to watch the outputs of each line of command. thanks in advance, George |
It's as simple as adding this line to the beginning of your file:
Code:
set -x Alunduil |
or changing
Code:
#!/bin/bash Code:
#!/bin/bash -x You can also run the script with: Code:
bash -x [yourscript] |
Alunduil,
Quote:
Do you mean this command can enable shell script to run step-by-step (like the step-next feature of an IDE, for example, F6 in Eclipse in debug mode)? I have tried and it only prints out the commands (including output of command) contained in the script file and a sign '+' before each command. regards, George |
alienDog,
Quote:
regards, George |
Quote:
|
Yep. It not possible with default bash. What I'd suggest is placing a 'read' command to the points where you want the execution to pause. This way the execution stops at that point until you hit enter. You could also consider echoing something appropriate to screen at the certain points of the screen.
Code:
command1 http://www.tldp.org/LDP/Bash-Beginne...ect_02_03.html You might also want to take a look at separate bashdb debugger: http://bashdb.sourceforge.net/bashdb.html For that you will need bash 3.0 or later (you probably have that already, bash --version will tell). |
alienDog,
Quote:
regards, George |
Personally I also use the -v switch like so:
set -xv v => verbose |
chrism01,
Quote:
regards, George |
sh -x ./scriptname # also works.. ;)
|
Quote:
|
trickykid,
Quote:
regards, George |
alienDog,
Quote:
regards, George |
Maybe contact your ISP?
|
All times are GMT -5. The time now is 01:29 AM. |