Skip to content

Commit b75beda

Browse files
committed
Fix some issues reported by shellcheck (SC2004, SC2006)
Examples: In training/tesstrain.sh line 64: if (( ${LINEDATA} )); then ^-- SC2004: $/${} is unnecessary on arithmetic variables. In training/tesstrain.sh line 56: source `dirname $0`/language-specific.sh ^-- SC2006: Use $(..) instead of legacy `..`. Signed-off-by: Stefan Weil <[email protected]>
1 parent 13e46ae commit b75beda

File tree

5 files changed

+43
-43
lines changed

5 files changed

+43
-43
lines changed

Makefile.am

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ dist-hook:
3838
# Need to remove .svn directories from directories
3939
# added using EXTRA_DIST. $(distdir)/tessdata would in
4040
# theory suffice.
41-
rm -rf `find $(distdir) -name .svn`
42-
rm -rf `find $(distdir) -name .git`
43-
rm -rf `find $(distdir) -name .deps`
44-
rm -rf `find $(distdir) -name .libs`
45-
rm -rf `find $(distdir) -name *.o`
46-
rm -rf `find $(distdir) -name *.lo`
47-
rm -rf `find $(distdir) -name *.la`
48-
rm -rf `find $(distdir)/training -executable -type f`
41+
rm -rf $(find $(distdir) -name .svn)
42+
rm -rf $(find $(distdir) -name .git)
43+
rm -rf $(find $(distdir) -name .deps)
44+
rm -rf $(find $(distdir) -name .libs)
45+
rm -rf $(find $(distdir) -name *.o)
46+
rm -rf $(find $(distdir) -name *.lo)
47+
rm -rf $(find $(distdir) -name *.la)
48+
rm -rf $(find $(distdir)/training -executable -type f)
4949
rm -rf $(distdir)/doc/html/*
5050

5151
ScrollView.jar:

testing/reorgdata.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ do
3636
mkdir -p $new
3737
echo "Set $old -> $new"
3838
#The pages file had - instead of _ so fix it and add the extension.
39-
for page in `cat $old/PAGES`
39+
for page in $(cat $old/PAGES)
4040
do
4141
echo "${page%-*}_${page#*-}.$ext"
4242
done >$new/pages
43-
for f in `cat $new/pages`
43+
for f in $(cat $new/pages)
4444
do
4545
#Put a tif extension on the tif files.
4646
cp $old/${old}_B/$f $new/$f.tif

testing/runalltests.sh

+22-22
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,30 @@ do
8181
# Count the errors on all the pages.
8282
$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=$(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)
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 |
89-
tr -d '[:blank:]'`
90-
chacc=`head -5 testing/reports/$set.characc |tail -1 |cut -c1-9 |
91-
tr -d '[:blank:]'`
92-
wderrs=`head -4 testing/reports/$set.wordacc |tail -1 |cut -c1-9 |
93-
tr -d '[:blank:]'`
94-
wdacc=`head -5 testing/reports/$set.wordacc |tail -1 |cut -c1-9 |
95-
tr -d '[:blank:]'`
96-
nswderrs=`grep Total testing/reports/$set.wordacc |head -2 |tail -1 |
97-
cut -c10-17 |tr -d '[:blank:]'`
98-
nswdacc=`grep Total testing/reports/$set.wordacc |head -2 |tail -1 |
99-
cut -c19-26 |tr -d '[:blank:]'`
88+
cherrs=$(head -4 testing/reports/$set.characc |tail -1 |cut -c1-9 |
89+
tr -d '[:blank:]')
90+
chacc=$(head -5 testing/reports/$set.characc |tail -1 |cut -c1-9 |
91+
tr -d '[:blank:]')
92+
wderrs=$(head -4 testing/reports/$set.wordacc |tail -1 |cut -c1-9 |
93+
tr -d '[:blank:]')
94+
wdacc=$(head -5 testing/reports/$set.wordacc |tail -1 |cut -c1-9 |
95+
tr -d '[:blank:]')
96+
nswderrs=$(grep Total testing/reports/$set.wordacc |head -2 |tail -1 |
97+
cut -c10-17 |tr -d '[:blank:]')
98+
nswdacc=$(grep Total testing/reports/$set.wordacc |head -2 |tail -1 |
99+
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
105105
if [ -r testing/reports/$set.times ]
106106
then
107-
total_time=`timesum testing/reports/$set.times`
107+
total_time=$(timesum testing/reports/$set.times)
108108
if [ -r testing/reports/prev/$set.times ]
109109
then
110110
paste testing/reports/prev/$set.times testing/reports/$set.times |
@@ -125,9 +125,9 @@ do
125125
fi
126126
done
127127
# Compute grand total percent change.
128-
chdelta=`deltapc $totalerrs $totalolderrs`
129-
wdelta=`deltapc $totalwerrs $totaloldwerrs`
130-
nswdelta=`deltapc $totalnswerrs $totaloldnswerrs `
128+
chdelta=$(deltapc $totalerrs $totalolderrs)
129+
wdelta=$(deltapc $totalwerrs $totaloldwerrs)
130+
nswdelta=$(deltapc $totalnswerrs $totaloldnswerrs)
131131
tfile=$rdir/$vid.total.sum
132132
echo "$vid Total $totalerrs - $chdelta% $totalwerrs\
133133
- $wdelta% $totalnswerrs - $nswdelta%" >$tfile

training/tesstrain.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@
4545
# appropriate --fonts_dir path.
4646

4747

48-
source `dirname $0`/tesstrain_utils.sh
48+
source "$(dirname $0)/tesstrain_utils.sh"
4949

5050
ARGV=("$@")
5151
parse_flags
5252

5353
mkdir -p ${TRAINING_DIR}
5454
tlog "\n=== Starting training for language '${LANG_CODE}'"
5555

56-
source `dirname $0`/language-specific.sh
56+
source "$(dirname $0)/language-specific.sh"
5757
set_lang_specific_parameters ${LANG_CODE}
5858

5959
initialize_fontconfig
6060

6161
phase_I_generate_image 8
6262
phase_UP_generate_unicharset
6363
phase_D_generate_dawg
64-
if (( ${LINEDATA} )); then
64+
if ((LINEDATA)); then
6565
phase_E_extract_features "lstm.train" 8 "lstmf"
6666
make__lstmdata
6767
else

training/tesstrain_utils.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ OVERWRITE=0
2626
LINEDATA=0
2727
RUN_SHAPE_CLUSTERING=0
2828
EXTRACT_FONT_PROPERTIES=1
29-
WORKSPACE_DIR=`mktemp -d`
29+
WORKSPACE_DIR=$(mktemp -d)
3030

3131
# Logging helper functions.
3232
tlog() {
@@ -42,7 +42,7 @@ err_exit() {
4242
# if the program file is not found.
4343
# Usage: run_command CMD ARG1 ARG2...
4444
run_command() {
45-
local cmd=`which $1`
45+
local cmd=$(which $1)
4646
if [[ -z ${cmd} ]]; then
4747
err_exit "$1 not found"
4848
fi
@@ -95,7 +95,7 @@ parse_flags() {
9595
FONTS=""
9696
while test $j -lt ${#ARGV[@]}; do
9797
test -z "${ARGV[$j]}" && break
98-
test `echo ${ARGV[$j]} | cut -c -2` = "--" && break
98+
test $(echo ${ARGV[$j]} | cut -c -2) = "--" && break
9999
FONTS[$fn]="${ARGV[$j]}"
100100
fn=$((fn+1))
101101
j=$((j+1))
@@ -105,7 +105,7 @@ parse_flags() {
105105
exp=""
106106
while test $j -lt ${#ARGV[@]}; do
107107
test -z "${ARGV[$j]}" && break
108-
test `echo ${ARGV[$j]} | cut -c -2` = "--" && break
108+
test $(echo ${ARGV[$j]} | cut -c -2) = "--" && break
109109
exp="$exp ${ARGV[$j]}"
110110
j=$((j+1))
111111
done
@@ -219,7 +219,7 @@ generate_font_image() {
219219
--text=${TRAINING_TEXT} ${TEXT2IMAGE_EXTRA_ARGS}
220220
check_file_readable ${outbase}.box ${outbase}.tif
221221

222-
if (( ${EXTRACT_FONT_PROPERTIES} )) &&
222+
if ((EXTRACT_FONT_PROPERTIES)) &&
223223
[[ -r ${TRAIN_NGRAMS_FILE} ]]; then
224224
tlog "Extracting font properties of ${font}"
225225
run_command text2image ${common_args} --font="${font}" \
@@ -243,7 +243,7 @@ phase_I_generate_image() {
243243
CHAR_SPACING="0.0"
244244

245245
for EXPOSURE in $EXPOSURES; do
246-
if (( ${EXTRACT_FONT_PROPERTIES} )) && [[ -r ${BIGRAM_FREQS_FILE} ]]; then
246+
if ((EXTRACT_FONT_PROPERTIES)) && [[ -r ${BIGRAM_FREQS_FILE} ]]; then
247247
# Parse .bigram_freqs file and compose a .train_ngrams file with text
248248
# for tesseract to recognize during training. Take only the ngrams whose
249249
# combined weight accounts for 95% of all the bigrams in the language.
@@ -424,7 +424,7 @@ phase_C_cluster_prototypes() {
424424

425425
# Phase S : (S)hape clustering
426426
phase_S_cluster_shapes() {
427-
if (( ! ${RUN_SHAPE_CLUSTERING} )); then
427+
if ((! RUN_SHAPE_CLUSTERING)); then
428428
tlog "\n=== Shape Clustering disabled ==="
429429
return
430430
fi
@@ -557,7 +557,7 @@ make__traineddata() {
557557
mkdir -p ${OUTPUT_DIR}
558558
fi
559559
local destfile=${OUTPUT_DIR}/${LANG_CODE}.traineddata;
560-
if [[ -f ${destfile} ]] && (( ! ${OVERWRITE} )); then
560+
if [[ -f ${destfile} ]] && ((! OVERWRITE)); then
561561
err_exit "File ${destfile} exists and no --overwrite specified";
562562
fi
563563
tlog "Moving ${TRAINING_DIR}/${LANG_CODE}.traineddata to ${OUTPUT_DIR}"

0 commit comments

Comments
 (0)