Skip to content

Commit 389221e

Browse files
committed
run_diff.sh shellcheck fixes
* Replace backticks with $() * Double-quote filenames that might conceivably contain troublesome special chars (*, space etc)
1 parent dce6ae1 commit 389221e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

scripts/run_diff.sh

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
set -e
44

5-
script_folder=`dirname $0`
6-
absolute_repository_root=`git rev-parse --show-toplevel`
5+
script_folder=$(dirname "$0")
6+
absolute_repository_root=$(git rev-parse --show-toplevel)
77
mode=$1
88
modes="CPPLINT | DOXYGEN"
99

@@ -16,7 +16,7 @@ then
1616
exit 1
1717
fi
1818

19-
if ! [[ -e $script_folder/filter_by_lines.py ]]
19+
if ! [[ -e ${script_folder}/filter_by_lines.py ]]
2020
then
2121
echo "Filter script could not be found in the $script_folder directory"
2222
echo "Ensure filter_by_lines.py is inside the $script_folder directory then run again"
@@ -31,13 +31,13 @@ then
3131
exit 1
3232
fi
3333

34-
if ! [[ -e $script_folder/cpplint.py ]]
34+
if ! [[ -e "${script_folder}/cpplint.py" ]]
3535
then
3636
echo "Lint script could not be found in the $script_folder directory"
3737
echo "Ensure cpplint.py is inside the $script_folder directory then run again"
3838
exit 1
3939
else
40-
cmd='$script_folder/cpplint.py $file 2>&1 >/dev/null'
40+
cmd='${script_folder}/cpplint.py $file 2>&1 >/dev/null'
4141
fi
4242
elif [[ "$mode" == "DOXYGEN" ]]
4343
then
@@ -78,26 +78,26 @@ else
7878
git_merge_base_end="HEAD"
7979
fi
8080

81-
git_start=`git merge-base $git_start $git_merge_base_end`
81+
git_start=$(git merge-base $git_start $git_merge_base_end)
8282

8383
cleanup()
8484
{
85-
rm -f $diff_file $added_lines_file
85+
rm -f "$diff_file" "$added_lines_file"
8686
}
8787

8888
trap cleanup EXIT
8989

90-
diff_file=`mktemp`
91-
added_lines_file=`mktemp`
90+
diff_file=$(mktemp)
91+
added_lines_file=$(mktemp)
9292

9393
# Pass the output through iconv to remove any invalid UTF-8 (diff_to_added_lines.py will die otherwise)
9494

95-
git diff $git_start $git_end | iconv -t utf-8 -c > $diff_file
95+
git diff $git_start $git_end | iconv -t utf-8 -c > "$diff_file"
9696

9797
# Get the list of files that have changed, that end with lintable extensions
98-
diff_files=`git diff --name-only $git_start $git_end | grep "\.\(\(cpp\)\|\(hh\)\|\(cc\)\|h\)$" || true`
98+
diff_files=$(git diff --name-only $git_start $git_end | grep "\.\(\(cpp\)\|\(hh\)\|\(cc\)\|h\)$" || true)
9999

100-
$script_folder/diff_to_added_lines.py $diff_file $absolute_repository_root > $added_lines_file
100+
"${script_folder}/diff_to_added_lines.py" "$diff_file" "$absolute_repository_root" > "$added_lines_file"
101101

102102
for file in $diff_files; do
103103
file=$absolute_repository_root/$file
@@ -109,7 +109,7 @@ for file in $diff_files; do
109109

110110
# Run the linting script and filter:
111111
# The errors from the linter go to STDERR so must be redirected to STDOUT
112-
result=`eval $cmd | $script_folder/filter_by_diff.py $file $added_lines_file $absolute_repository_root`
112+
result=$(eval $cmd | "${script_folder}/filter_by_lines.py" "$file" "$added_lines_file" "$absolute_repository_root")
113113

114114
# Providing some errors were relevant we print them out
115115
if [ "$result" ]

0 commit comments

Comments
 (0)