Skip to content

Commit 43c4e6b

Browse files
grischemaurerle
authored andcommitted
ffac-ssid-changer: replace string indexing
In POSIX sh, string indexing is not defined. This only works in ksh, bash or busybox's modified version of ash. Does not work in dash, ash, etc. Fixes: SC3057 (warning): In POSIX sh, string indexing is undefined.
1 parent 810703f commit 43c4e6b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ if [ "$SETTINGS_SUFFIX" = 'nodename' ]; then
5555
# 32 would be possible as well
5656
if [ ${#SUFFIX} -gt $((30 - ${#PREFIX})) ]; then
5757
# calculate the length of the first part of the node identifier in the offline-ssid
58-
HALF=$(( (28 - ${#PREFIX} ) / 2 ))
59-
# jump to this charakter for the last part of the name
60-
SKIP=$(( ${#SUFFIX} - HALF ))
58+
max_suffix_length=$(( (28 - ${#PREFIX} ) / 2 ))
6159
# use the first and last part of the nodename for nodes with long name
62-
SUFFIX=${SUFFIX:0:$HALF}...${SUFFIX:$SKIP:${#SUFFIX}}
60+
suffix_first_chars="$(printf '%s' "$SUFFIX" | head -c ${max_suffix_length})"
61+
suffix_last_chars="$(printf '%s' "$SUFFIX" | tail -c ${max_suffix_length})"
62+
SUFFIX="${suffix_first_chars}...${suffix_last_chars}"
6363
fi
6464
elif [ "$SETTINGS_SUFFIX" = 'mac' ]; then
6565
SUFFIX="$(uci -q get network.bat0.macaddr | /bin/sed 's/://g')"

0 commit comments

Comments
 (0)