Problem
I tried to extract the signal level for wifi in the following way, in a bash script (quotes seem to make no difference):
string="$(iwconfig wlan0 | grep -I Signal)"
If I echo $string
, I get what I expect:
Link Quality=63/70 Signal level=-47dBm
But if I try to get a substring, echo ${string:5}
, it returns the same thing.
Debuging:
If I paste the output of wconfig wlan0 | grep -I Signal
directly into the variable: string="Link Quality=63/70 Signal level=-47dBm"
then everything works as expected.
echo $string
# Link Quality=63/70 Signal level=-47dBm
echo ${string:5}
# Quality=63/70 Signal level=-47dBm
Question: According to the internet, all bash variables are stored as character strings. Thus, the debugging result should have been the same as my original problem. Is there some reason it is not parsed as text in the original problem?