8.8 Debugging



8.8.1 Debugging

When the created program does not work, you have to investigate what the problem is. This is called debugging. It is necessary to embed the code on which a variable is displayed, It is also necessary to embed the code on which the run route of a program is displayed. This takes a lot of time and efforts. Therefore, the tool which supports debugging is prepared for many program language. For shell script, the debug mode is prepared.

8.8.2 sh Command

The sh itself is a command which starts shell script. When it runs with -x option, the shell script will be performed displaying the contents of the command or the variable. Let's perform sample.sh described before by the sh command.

Example

$ sh -x ./sample.sh ↵
+ true
+ echo 'Continue? (y/n)'
Continue? (y/n)
+ read input
y ↵                         Inputted y
+ case $input in
+ continue
+ true
+ echo 'Continue? (y/n)'
Continue? (y/n)
+ read input
n ↵                         Inputted n
+ case $input in
+ break



Previous Next