This can be done with a relatively simple script. For both options, make sure you have a debug-config
file containing what's in your question, except it also need to contain the paths: (else the script will not know the exact location of each file)
0 ${edvart_trkrc}/marinex.rc
0 ${edvart_trkrc}/firefly.rc
0 ${edvart_trkrc}/navaid.rc
1 ${baikonur_trkrc}/buranex.rc
0 ${gunars_trkrc}/comseq.rc
0 ${gunars_trkrc}/comint.rc
Option 1: Modify the source files themselves for debugging
First, in all your source files (marinex.rc
, firefly.rc
etc.) make sure the following line is the first line: (sets debugging off by default)
set +xv
Now create a debug-set
script and make it executable:
#!/bin/bash
# define paths
edvart_trkrc="/define/the/path1"
baikonur_trkrc="/define/the/path2"
gunars_trkrc="/define/the/path3"
# reading each line
while read -r line; do
# define options
debug_st=$(echo "$line" | awk '{ print $1 }')
filename=$(echo "$line" | awk '{ print $2 }')
# change debug setting
case "$debug_st" in
0)
sed -i 's/set -xv/set +xv/g' "$filename"
;;
1)
sed -i 's/set +xv/set -xv/g' "$filename"
;;
esac
done < ./debug-config
Make sure you define any variable paths included in the debug-config
file.
Now, when you run the ./debug-set
script, it will change the first line of each sourced file to set +xv
if the config contains a 0
, and set -xv
if the config contains a 1
.
In any other cases, it's not going to do anything. This will easily allow anyone to apply the debug configuration set in debug-config
to the source files.
Option 2: Set the debug toggles directly in the script sourcing the files
Another way to go about this is to set the debug info directly in the script sourcing the files. This works much like the debug-set
script, except this "just" sources the files with or without debugging.
So have your source-script
instead of doing this:
source "${edvart_trkrc}/marinex.rc"
source "${edvart_trkrc}/firefly.rc"
source "${edvart_trkrc}/navaid.rc"
source "${baikonur_trkrc}/buranex.rc"
source "${gunars_trkrc}/comseq.rc"
source "${gunars_trkrc}/comint.rc"
Then do this:
#!/bin/bash
# reading each line
while read -r line; do
# define options
debug_st=$(echo "$line" | awk '{ print $1 }')
filename=$(echo "$line" | awk '{ print $2 }')
# change debug setting
case "$debug_st" in
0)
set +xv
source "$filename"
;;
1)
set -xv
source "$filename"
set +xv
;;
esac
done < ./debug-config
Now the command sourcing each file sets the proper debug option before sourcing, and turns it off again afterwards if it was on.
The only downside to this is, that since the debug option is set right before the file is sourced, the output of the entire file (the source
command) will be part of the debugging information.