Skip to content

Commit 34b750e

Browse files
committed
Quote integer variables for consistency and safety
This adds quotes around all integer variable usages to follow defensive programming best practices: - Quote variable assignments: ret="$?" - Quote in numerical comparisons: [ "$ret" -eq 0 ] - Quote in array indexing: ${MESSAGES["$ret"]} - Quote in exit statements: exit "$ret" While unquoted variables work in numeric contexts, quoting ensures: 1. Consistent coding style across the codebase 2. Protection against unexpected word splitting 3. Better shellcheck compliance 4. Clearer intent that these are variable expansions
1 parent a2ccebc commit 34b750e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.ci/autorun.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ expect "# " { send "uname -a\n" } timeout { exit 2 }
1212
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
1313
DONE
1414

15-
ret=$?
15+
ret="$?"
1616

1717
MESSAGES=("OK!" \
1818
"Fail to boot" \
1919
"Fail to login" \
2020
"Fail to run commands" \
2121
)
2222

23-
if [ $ret -eq 0 ]; then
24-
print_success "${MESSAGES[$ret]}"
23+
if [ "$ret" -eq 0 ]; then
24+
print_success "${MESSAGES["$ret"]}"
2525
else
26-
print_error "${MESSAGES[$ret]}"
26+
print_error "${MESSAGES["$ret"]}"
2727
fi
2828

29-
exit ${ret}
29+
exit "$ret"

.ci/test-netdev.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ for NETDEV in "${NETWORK_DEVICES[@]}"; do
5858
TEST_NETDEV "$NETDEV"
5959
done
6060

61-
ret=$?
61+
ret="$?"
6262

6363
MESSAGES=("OK!" \
6464
"Fail to boot" \
@@ -67,10 +67,10 @@ MESSAGES=("OK!" \
6767
"Fail to transfer packet" \
6868
)
6969

70-
if [ $ret -eq 0 ]; then
71-
print_success "${MESSAGES[$ret]}"
70+
if [ "$ret" -eq 0 ]; then
71+
print_success "${MESSAGES["$ret"]}"
7272
else
73-
print_error "${MESSAGES[$ret]}"
73+
print_error "${MESSAGES["$ret"]}"
7474
fi
7575

76-
exit ${ret}
76+
exit "$ret"

0 commit comments

Comments
 (0)