From 779ad6937ba402b3d33265b28d6f2981b85456b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 13 Apr 2017 02:33:05 +0200 Subject: [PATCH] Convert signal into positive value The signal can be a negative dBm or a positive percentage depending of the capabilities of the driver. We must convert the value into a positive integer to allow to sort in all cases. --- wiconfig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wiconfig b/wiconfig index ce2e2b9..90b6a0a 100644 --- a/wiconfig +++ b/wiconfig @@ -200,7 +200,7 @@ function scan { # IFS=' "' # IFS=$oIFS echo -n > "$output" - typeset _nwids _args _nwid + typeset _nwids _args _nwid _signal ! $quiet && echo "Performing wireless scan..." # Parse ifconfig nwid output for sorting @@ -266,7 +266,10 @@ function scan { # MAC echo -n "|$4" >> $output # Signal quality - printf "|%02d" ${5%dBm} >> $output + _signal=${5%dBm} # Remove dBm suffix + _signal=${_signal%\%} # Remove % suffix + _signal=${_signal#-} # Make signal always positive + printf "|%02d" ${_signal} >> $output # Speed echo -n "|$6" >> $output # Options @@ -379,7 +382,7 @@ function menu { echo for _i in ${index[@]}; do printf "%3d) %-40s %-6s %-10s\n" \ - $_i "${nwid[$_i]}" "${db[$_i]}dB" "${access[$_i]}" + $_i "${nwid[$_i]}" "${db[$_i]}" "${access[$_i]}" done echo read choice?"Enter the number of the network to connect to (or r to rescan or q to quit): "