Views:
1,900β
Votes: 6β
Tags:
command-line
bash
scripts
text
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1163607
Title:
Variable doesn't parse as string
ID:
/2019/08/05/Variable-doesn_t-parse-as-string
Created:
August 5, 2019
Edited: August 5, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
This works on my machine:
$ string="$(iwconfig wlp60s0 | grep -I Signal)"
$ echo $string
Link Quality=68/70 Signal level=-42 dBm
$ echo $string | cut -d' ' -f4,5
level=-42 dBm
- For your machine replace
wlp60s0
withwlan0
. - Note this is using Ubuntu 16.04 and Ubuntu 19.04 where there is a space between
42
anddBm
. As such thecut
command is instructed to print fields #4 and #5. In your question there is no space so Iβm not sure what version you are using.
You could also use:
$ echo $string | cut -d'=' -f3
-42 dBm
- In this case
cut
is told to use=
as field delimiter.
If you want to use ${string...}
though the correct syntax is:
$ echo ${string##*=}
-38 dBm
$ echo "${string##*=}"
-38 dBm
Either method will work to take the substring after the last =
. The original method of 5
in your question I donβt understand how it can work.