Skip to content

Commit 934e612

Browse files
committed
testing: Fix warnings from shellcheck
Fix these kinds of warnings: SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. SC2086: Double quote to prevent globbing and word splitting. SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. Signed-off-by: Stefan Weil <[email protected]>
1 parent afd6b7d commit 934e612

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

testing/counttestset.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ do
4949
fi
5050
# echo "$srcdir/$page.tif"
5151
# Count character errors.
52-
testing/unlv/accuracy $srcdir/$page.txt $resdir/$page.txt $resdir/$page.acc
52+
testing/unlv/accuracy "$srcdir/$page.txt" "$resdir/$page.txt" "$resdir/$page.acc"
5353
accfiles="$accfiles $resdir/$page.acc"
5454
# Count word errors.
55-
testing/unlv/wordacc $srcdir/$page.txt $resdir/$page.txt $resdir/$page.wa
55+
testing/unlv/wordacc "$srcdir/$page.txt" "$resdir/$page.txt" "$resdir/$page.wa"
5656
wafiles="$wafiles $resdir/$page.wa"
57-
done <$pages
58-
testing/unlv/accsum $accfiles >testing/reports/$setname.characc
59-
testing/unlv/wordaccsum $wafiles >testing/reports/$setname.wordacc
57+
done <"$pages"
58+
testing/unlv/accsum "$accfiles" >"testing/reports/$setname.characc"
59+
testing/unlv/wordaccsum "$wafiles" >"testing/reports/$setname.wordacc"
6060

6161

testing/reorgdata.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ do
3333
if [ -r "$old/PAGES" ]
3434
then
3535
new=${s#*/}.$ext
36-
mkdir -p $new
36+
mkdir -p "$new"
3737
echo "Set $old -> $new"
3838
#The pages file had - instead of _ so fix it and add the extension.
3939
for page in $(cat $old/PAGES)
4040
do
4141
echo "${page%-*}_${page#*-}.$ext"
42-
done >$new/pages
43-
for f in $(cat $new/pages)
42+
done >"$new/pages"
43+
for f in $(cat "$new/pages")
4444
do
4545
#Put a tif extension on the tif files.
46-
cp $old/${old}_B/$f $new/$f.tif
46+
cp "$old/${old}_B/$f" "$new/$f.tif"
4747
#Put a uzn extension on the zone files.
48-
cp $old/${old}_B/${f}Z $new/$f.uzn
48+
cp "$old/${old}_B/${f}Z" "$new/$f.uzn"
4949
#Cat all the truth files together and put into a single txt file.
50-
cat $old/${old}_GT/${f%.$ext}.Z* >$new/$f.txt
50+
cat "$old/${old}_GT/${f%.$ext}".Z* >"$new/$f.txt"
5151
done
5252
fi
5353
done

testing/runalltests.sh

+27-27
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ then
2525
echo "Run $0 from the tesseract-ocr root directory!"
2626
exit 1
2727
fi
28-
if [ ! -r api/tesseract -a ! -r tesseract.exe ]
28+
if [ ! -r api/tesseract ] && [ ! -r tesseract.exe ]
2929
then
3030
echo "Please build tesseract before running $0"
3131
exit 1
3232
fi
33-
if [ ! -r testing/unlv/accuracy -a ! -r testing/unlv/accuracy.exe ]
33+
if [ ! -r testing/unlv/accuracy ] && [ ! -r testing/unlv/accuracy.exe ]
3434
then
3535
echo "Please download the UNLV accuracy tools (and build) to testing/unlv"
3636
exit 1
@@ -39,7 +39,7 @@ fi
3939
#deltapc new old calculates the %change from old to new
4040
deltapc() {
4141
awk ' BEGIN {
42-
printf("%.2f", 100.0*('$1'-'$2')/'$2');
42+
printf("%.2f", 100.0*('"$1"'-'"$2"')/'"$2"');
4343
}'
4444
}
4545

@@ -53,7 +53,7 @@ total = 0.0;
5353
}
5454
END {
5555
printf("%.2f\n", total);
56-
}' $1
56+
}' "$1"
5757
}
5858

5959
imdir="$1"
@@ -74,47 +74,47 @@ totaloldwerrs=0
7474
totaloldnswerrs=0
7575
for set in $testsets
7676
do
77-
if [ -r $imdir/$set/pages ]
77+
if [ -r "$imdir/$set/pages" ]
7878
then
7979
# Run tesseract on all the pages.
80-
$bindir/runtestset.sh $imdir/$set/pages
80+
$bindir/runtestset.sh "$imdir/$set/pages"
8181
# Count the errors on all the pages.
82-
$bindir/counttestset.sh $imdir/$set/pages
82+
$bindir/counttestset.sh "$imdir/$set/pages"
8383
# Get the old character word and nonstop word errors.
84-
olderrs=$(cat testing/reports/1995.$set.sum | cut -f3)
85-
oldwerrs=$(cat testing/reports/1995.$set.sum | cut -f6)
86-
oldnswerrs=$(cat testing/reports/1995.$set.sum | cut -f9)
84+
olderrs=$(cut -f3 "testing/reports/1995.$set.sum")
85+
oldwerrs=$(cut -f6 "testing/reports/1995.$set.sum")
86+
oldnswerrs=$(cut -f9 "testing/reports/1995.$set.sum")
8787
# Get the new character word and nonstop word errors and accuracy.
88-
cherrs=$(head -4 testing/reports/$set.characc |tail -1 |cut -c1-9 |
88+
cherrs=$(head -4 "testing/reports/$set.characc" |tail -1 |cut -c1-9 |
8989
tr -d '[:blank:]')
90-
chacc=$(head -5 testing/reports/$set.characc |tail -1 |cut -c1-9 |
90+
chacc=$(head -5 "testing/reports/$set.characc" |tail -1 |cut -c1-9 |
9191
tr -d '[:blank:]')
92-
wderrs=$(head -4 testing/reports/$set.wordacc |tail -1 |cut -c1-9 |
92+
wderrs=$(head -4 "testing/reports/$set.wordacc" |tail -1 |cut -c1-9 |
9393
tr -d '[:blank:]')
94-
wdacc=$(head -5 testing/reports/$set.wordacc |tail -1 |cut -c1-9 |
94+
wdacc=$(head -5 "testing/reports/$set.wordacc" |tail -1 |cut -c1-9 |
9595
tr -d '[:blank:]')
96-
nswderrs=$(grep Total testing/reports/$set.wordacc |head -2 |tail -1 |
96+
nswderrs=$(grep Total "testing/reports/$set.wordacc" |head -2 |tail -1 |
9797
cut -c10-17 |tr -d '[:blank:]')
98-
nswdacc=$(grep Total testing/reports/$set.wordacc |head -2 |tail -1 |
98+
nswdacc=$(grep Total "testing/reports/$set.wordacc" |head -2 |tail -1 |
9999
cut -c19-26 |tr -d '[:blank:]')
100100
# Compute the percent change.
101-
chdelta=$(deltapc $cherrs $olderrs)
102-
wdelta=$(deltapc $wderrs $oldwerrs)
103-
nswdelta=$(deltapc $nswderrs $oldnswerrs)
101+
chdelta=$(deltapc "$cherrs" "$olderrs")
102+
wdelta=$(deltapc "$wderrs" "$oldwerrs")
103+
nswdelta=$(deltapc "$nswderrs" "$oldnswerrs")
104104
sumfile=$rdir/$vid.$set.sum
105-
if [ -r testing/reports/$set.times ]
105+
if [ -r "testing/reports/$set.times" ]
106106
then
107-
total_time=$(timesum testing/reports/$set.times)
108-
if [ -r testing/reports/prev/$set.times ]
107+
total_time=$(timesum "testing/reports/$set.times")
108+
if [ -r "testing/reports/prev/$set.times" ]
109109
then
110-
paste testing/reports/prev/$set.times testing/reports/$set.times |
111-
awk '{ printf("%s %.2f\n", $1, $4-$2); }' |sort -k2n >testing/reports/$set.timedelta
110+
paste "testing/reports/prev/$set.times" "testing/reports/$set.times" |
111+
awk '{ printf("%s %.2f\n", $1, $4-$2); }' |sort -k2n >"testing/reports/$set.timedelta"
112112
fi
113113
else
114114
total_time='0.0'
115115
fi
116116
echo "$vid $set $cherrs $chacc $chdelta% $wderrs $wdacc\
117-
$wdelta% $nswderrs $nswdacc $nswdelta% ${total_time}s" >$sumfile
117+
$wdelta% $nswderrs $nswdacc $nswdelta% ${total_time}s" >"$sumfile"
118118
# Sum totals over all the testsets.
119119
let totalerrs=totalerrs+cherrs
120120
let totalwerrs=totalwerrs+wderrs
@@ -130,5 +130,5 @@ wdelta=$(deltapc $totalwerrs $totaloldwerrs)
130130
nswdelta=$(deltapc $totalnswerrs $totaloldnswerrs)
131131
tfile=$rdir/$vid.total.sum
132132
echo "$vid Total $totalerrs - $chdelta% $totalwerrs\
133-
- $wdelta% $totalnswerrs - $nswdelta%" >$tfile
134-
cat $rdir/1995.*.sum $rdir/$vid.*.sum >$rdir/$vid.summary
133+
- $wdelta% $totalnswerrs - $nswdelta%" >"$tfile"
134+
cat $rdir/1995.*.sum "$rdir/$vid".*.sum >"$rdir/$vid".summary

testing/runtestset.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
if [ $# -ne 1 -a $# -ne 2 ]
18+
if [ $# -ne 1 ] && [ $# -ne 2 ]
1919
then
2020
echo "Usage:$0 pagesfile [-zoning]"
2121
exit 1
@@ -42,7 +42,7 @@ fi
4242
pages=$1
4343
imdir=${pages%/pages}
4444
setname=${imdir##*/}
45-
if [ $# -eq 2 -a "$2" = "-zoning" ]
45+
if [ $# -eq 2 ] && [ "$2" = "-zoning" ]
4646
then
4747
config=unlv.auto
4848
resdir=testing/results/zoning.$setname
@@ -51,8 +51,8 @@ else
5151
resdir=testing/results/$setname
5252
fi
5353
echo -e "Testing on set $setname in directory $imdir to $resdir\n"
54-
mkdir -p $resdir
55-
rm -f testing/reports/$setname.times
54+
mkdir -p "$resdir"
55+
rm -f "testing/reports/$setname.times"
5656
while read page dir
5757
do
5858
# A pages file may be a list of files with subdirs or maybe just
@@ -64,15 +64,15 @@ do
6464
srcdir="$imdir"
6565
fi
6666
# echo "$srcdir/$page.tif"
67-
$tess $srcdir/$page.tif $resdir/$page --psm 6 $config 2>&1 |grep -v "OCR Engine"
67+
$tess "$srcdir/$page.tif" "$resdir/$page" --psm 6 $config 2>&1 |grep -v "OCR Engine"
6868
if [ -r times.txt ]
6969
then
7070
read t <times.txt
71-
echo "$page $t" >>testing/reports/$setname.times
71+
echo "$page $t" >>"testing/reports/$setname.times"
7272
echo -e "\033M$page $t"
7373
if [ "$t" = "Command terminated by signal 2" ]
7474
then
7575
exit 0
7676
fi
7777
fi
78-
done <$pages
78+
done <"$pages"

0 commit comments

Comments
 (0)