I would like to call out to any SH scripting Gurus out there for some assistance.
During my time messing with my WiFi Router, I managed to created some rogue variables in NVRAM that I can’t seem to get rid of, short of doing a full NVRAM CLEAR and starting over setting up my Router. It’s not that big of a deal to do so, but I want to see if I can fix the problem without clearing NVRAM. Let’s see what we have…
# nvram show | grep wl0.1_wpa_psk
wl0.1_wpa_psk=goodfriends
wl0.1_wpa_psk!={SETTING:WiFiPW}!!
# nvram show | grep "wl0.1_wpa_psk" | grep "SETTING"
wl0.1_wpa_psk!={SETTING:WiFiPW}!!
The bad string is represented by the following, where I’ve used the exclamation (!) as a placeholder for some embedded invisible character(s). The ! may be 1 character, or 2 or 3, or more - I don’t know.
wl0.1_wpa_psk!={SETTING:WiFiPW}!!
^ ^^
What I’m trying to accomplish is this:
nvram unset wl0.1_wpa_psk!
So my methodology is to attempt to capture the bad character(s) into a variable such as $badchars, then do:
nvram unset "wl0.1_wpa_psk$badchars"
This is where I need the help. How do I capture the bad character(s) when I don’t know the length, using for example sed?
badstring=$(nvram show | grep "wl0.1_wpa_psk" | grep "SETTING")
badchars=$(echo $badstring | sed 's/wl0.1_wpa_psk//g')
At this point $badchars should contain !={SETTING:WiFiPW}!!, but we’re not done. I want to filter it down to the leading ! and get rid of all the rest.
Not knowing the character count of the leading ! (the character(s) before =), I’m stuck. Maybe I should use awk at this point to split on = and take the first array element… having trouble with the syntax.
I think I have it:
badpart=$(echo $badchars | awk '{split($0,bad,"=")} END{print bad[1]}')


