Usually: Go into your UEFI Settings and disable" wake up by usb inputs" at the power management section. The option can be called differently.
If not possible, then here is a more reliable version of your script:
#!/bin/bash
# Toggle wakeup device (enabled/disabled)
echo "XHC" > /proc/acpi/wakeup
# If enabled, it will be disabled or if disabled, it will be enabled.
Check to which address path it is symlinked to:
file /sys/bus/usb/devices/*
For example: 0000:00:14.0
and compare with:
cat /proc/acpi/wakeup
Adjust “XHC” above.
You can also use something like that:
while read line
do
mapfile -t -d' ' <<<"$line"
[[ "${MAPFILE[2]}" == '*disabled' ]] && continue
if [[ "${MAPFILE[2]}" == '*enabled' ]] \
&& [[ "${MAPFILE[0]}" == 'XHC' ]]; then
echo "Disabling ${MAPFILE[3]}"
# Uncomment the following to run it:
# echo "${MAPFILE[0]}" > /proc/acpi/wakeup
fi
done < <(cat /proc/acpi/wakeup | tr '\t' ' ' | tr -s ' ')