OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Finding The Problem Area

In some scripts, particularly long ones, it is sometimes useful to isolate the area of the script that is related to the problem. This won’t always be the actual error, but isolation will often provide insights into the actual cause. One technique that can be used to isolate code is “commenting out” sections of a script. For example, our file deletion fragment could be modified to determine if the removed section was related to an error:



if [[ -d $dir_name ]]; then if cd $dir_name; then

rm *

else

echo "cannot cd to '$dir_name'" >&2 exit 1

fi

# else

# echo "no such directory: '$dir_name'" >&2

# exit 1

fi

if [[ -d $dir_name ]]; then if cd $dir_name; then

rm *

else

echo "cannot cd to '$dir_name'" >&2 exit 1

fi

# else

# echo "no such directory: '$dir_name'" >&2

# exit 1

fi


By placing comment symbols at the beginning of each line in a logical section of a script, we prevent that section from being executed. Testing can then be performed again, to see if the removal of the code has any impact on the behavior of the bug.


Top OS Cloud Computing at OnWorks: