Skip to content

Instantly share code, notes, and snippets.

@matthew-nm
Forked from cameronism/rfkill-toggle.sh
Last active October 19, 2017 06:52
Show Gist options
  • Save matthew-nm/bea59084d72e90448fd60b2fc5f96e5a to your computer and use it in GitHub Desktop.
Save matthew-nm/bea59084d72e90448fd60b2fc5f96e5a to your computer and use it in GitHub Desktop.
rfkill-toggle.sh
#!/bin/bash
# Usage ./rfkill-toggle.sh [IDENTIFIER]
# where IDENTIFIER is the index no. of an rfkill switch or one of:
# wifi wlan bluetooth uwb ultrawideband wimax wwan gps fm nfc
ID=`rfkill list "$1" | head -n 1 | cut -d : -f 1`
SOFT="/sys/class/rfkill/rfkill$ID/soft"
if [ ! -f "$SOFT" ]; then
echo "no such identifier"
exit 1
fi
ACTION="block"
if [ $(cat "$SOFT") -eq 1 ]; then
ACTION="unblock"
fi
rfkill "$ACTION" "$ID"
@matthew-nm
Copy link
Author

Forked from @cameronism

Updated ID to use head line filter (not byte filter) as well as ":" delimiter for cut.

Updated final command to not use sudo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment