diff --git a/lsusb b/lsusb index 93f0002..eb8e5fe 100755 --- a/lsusb +++ b/lsusb @@ -10,10 +10,13 @@ shopt -s extglob verbose() { system_profiler SPUSBDataType 2>/dev/null + + # Restore the IFS and exit + cleanup } version() { - echo "lsusb for macOS 1.1.2" + echo "lsusb for macOS 1.1.3" } help() { @@ -32,6 +35,9 @@ List USB devices -V Show version of program -h Show usage and help EOM + +# Restore the IFS and exit +cleanup } usage() { @@ -121,7 +127,7 @@ parse() { esac fi - if [ ${#bus_num} -ne 0 ]; then + if [ ${#bus_num} != 0 ]; then # Convert bus number from hexadecimal to decimal. bus_num=$(printf "%03d" "0x0$bus_num") else @@ -149,51 +155,55 @@ parse() { # Filter by VID/PID if given as input argument. if [ -n "$vid_pid" ]; then # Convert input vid to lower case. + # shellcheck disable=SC2143 if [ -n "$(echo "$vid_pid" | grep ':')" ]; then arg_vid=$(echo "$vid_pid" | awk -F':' '{print $1}' | sed 's/^0x//' | tr '[:upper:]' '[:lower:]') if [ -n "$arg_vid" ]; then - if [ $((16#$arg_vid)) -ne $((16#$VID)) ]; then + if [ $((16#$arg_vid)) != $((16#$VID)) ]; then return 1 fi fi arg_pid=$(echo "$vid_pid" | awk -F':' '{print $2}' | sed 's/^0x//' | tr '[:upper:]' '[:lower:]') if [ -n "$arg_pid" ]; then - if [ $((16#$arg_pid)) -ne $((16#$PID)) ]; then + if [ $((16#$arg_pid)) != $((16#$PID)) ]; then return 1 fi fi else # Missing a colon is a syntax error in -d option help + # shellcheck disable=SC2317 exit 1 fi fi # Filter by BUS/DEV if given as input argument. if [ -n "$bus_dev" ]; then + # shellcheck disable=SC2143 if [ -n "$(echo "$bus_dev" | grep ':')" ]; then # Convert input bus to lower case arg_bus=$(echo "$bus_dev" | awk -F':' '{print $1}' | sed 's/^ *//; s/ *$//') if [ -n "$arg_bus" ]; then - if [ "$arg_bus" -ne "$bus_num" ]; then + if [ "$arg_bus" != "$bus_num" ]; then return 1 fi fi # Strip leading and trailing spaces from argument. arg_dev=$(echo "$bus_dev" | awk -F':' '{print $2}' | sed 's/^ *//; s/ *$//') if [ -n "$arg_dev" ]; then - if [ "$arg_dev" -ne "$device_num" ]; then + if [ "$arg_dev" != "$device_num" ]; then return 1 fi fi fi fi # Special case: no colon after -s means device-only. + # shellcheck disable=SC2143 if [ -z "$(echo "$bus_dev" | grep ':')" ]; then # Strip leading and trailing spaces from argument. arg_dev=$(echo "$bus_dev" | sed 's/^ *//; s/ *$//') if [ -n "$arg_dev" ]; then - if [ "$arg_dev" -ne "$device_num" ]; then + if [ "$arg_dev" != "$device_num" ]; then return 1 fi fi @@ -222,6 +232,7 @@ setup() { cleanup() { IFS=$OIFS + # shellcheck disable=SC2086 exit $exitcode } @@ -260,7 +271,7 @@ tree() { for device in $(get_devices); do # Skip null device lines - if [ "${#device}" -ne 1 ]; then + if [ "${#device}" != 1 ]; then parse buildtreeline treedata="$treedata""${treeline}"$'\n'