Repository navigation
Expand file tree
/
Copy path25_code_debugging.sh
More file actions
66 lines (40 loc) · 1.61 KB
/
Copy path25_code_debugging.sh
File metadata and controls
66 lines (40 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#################################
# Created : 10-3-2024
# Code : Code Debugging;Identifying and resolving errors and issues in scripts to ensure functionality and reliability.
#################################
<<comment
** Code debugging is the process of identifying and fixing errors in your code.
It's a crucial skill for any programmer, and Bash scripting is no exception.
** Several things can go wrong with your Bash script:
1) Syntax errors:
These are typos or mistakes in the script's grammar that prevent it from even running.
2) Logical errors:
The script runs without errors, but it doesn't produce the intended results due to flaws in the logic.
3) Runtime errors:
These errors occur during script execution due to unexpected input or conditions.
** How you can debug your code ?
1) Using set options:
set -x
YOUR CODE SHOULD BE HERE
set +x
2) Using echo statements:
Add echo statements throughout your script to print the values of variables at different points.
This helps you track the flow of the script and identify where things might be going wrong.
3) Using the trap command:
The trap command allows you to define an action to be taken when a specific signal is received.
You can use it to trigger specific debugging actions when errors occur.
comment
#---------------------------------
# Example No 1 : debugging using set -x, set +x method
#---------------------------------
set -x
counter=1
until [ $counter -eq 10 ]; do
echo "Number: $counter"
counter=$((counter + 1))
done
set +x
#---------------------------------
# Example No 2 :
#---------------------------------