Debugging The Original:
Script gets executed in debug mode if we specify sh -x while calling.
1)By sh -x
Say script.sh is file with content
$cat script.sh
count=1
while [ $count -lt 4 ]
do
echo"iteration: $count"
count=`expr $count + 1`
done
$./script.sh
iteration: 1
iteration: 2
iteration: 3
+ count=1
+ [ 1 -lt 4 ]
+ iteration: $count"
iteration: 1
+ count=2
+ [ 2 -lt 4 ]
+ iteration: $count"
iteration: 2
+ count=3
+ [ 3 -lt 4 ]
+ iteration: $count"
iteration: 3
+ count=3
+ [ 4 -lt 4 ]
The actual problem is here ...
As I mentioned debugging can be done by specifying sh -x while executing the script but the same will not work in case any child script gets called by other.
In this case the same action can be performed by specifying set -x after she-band statement in child script
$sh -x ./script.sh
iteration: 1
iteration: 2
iteration: 3
+ count=1
+ [ 1 -lt 4 ]
+ iteration: $count"
iteration: 1
+ count=2
+ [ 2 -lt 4 ]
+ iteration: $count"
iteration: 2
+ count=3
+ [ 3 -lt 4 ]
+ iteration: $count"
iteration: 3
+ count=3
+ [ 4 -lt 4 ]
For Child Scripts ::
The actual problem is here ...
As I mentioned debugging can be done by specifying sh -x while executing the script but the same will not work in case any child script gets called by other.
In this case the same action can be performed by specifying set -x after she-band statement in child script
No comments:
Post a Comment