Skip to content

Commit a7ecc20

Browse files
committed
ffac-ssid-changer: use globs instead of ls output
Fixes shellcheck SC2045: Iterating over ls output is fragile. Use globs.
1 parent 394a373 commit a7ecc20

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ffac-ssid-changer/shsrc/ssid-changer.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ if [ "$CHECK" -gt 0 ] || [ "$DISABLED" = '1' ]; then
121121
echo "node is online"
122122
LOOP=1
123123
# check status for all physical devices
124-
for HOSTAPD in $(ls /var/run/hostapd-phy*); do
124+
for HOSTAPD in /var/run/hostapd-phy*; do
125+
[ -e "$HOSTAPD" ] || break # handle the case of no hostapd-phy* files
125126
ONLINE_SSID="$(echo $ONLINE_SSIDs | awk -F '~' -v l=$((LOOP*2)) '{print $l}')"
126127
LOOP=$((LOOP+1))
127128
CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
@@ -165,7 +166,8 @@ elif [ "$CHECK" -eq 0 ]; then
165166
if [ $OFF_COUNT -ge $(($T / 2)) ]; then
166167
# node was offline more times than half of switch_timeframe (or than $FIRST)
167168
LOOP=1
168-
for HOSTAPD in $(ls /var/run/hostapd-phy*); do
169+
for HOSTAPD in /var/run/hostapd-phy*; do
170+
[ -e "$HOSTAPD" ] || break # handle the case of no hostapd-phy* files
169171
ONLINE_SSID="$(echo $ONLINE_SSIDs | awk -F '~' -v l=$((LOOP*2)) '{print $l}')"
170172
LOOP=$((LOOP+1))
171173
CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)"

0 commit comments

Comments
 (0)