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]}')