I am trying to assign Link Quality (percentage) from iwconfig to a variable in a .sh file. This is for a conky theme I'm making. To do this I have the following:

lnk=$(iwconfig mlan0 | awk '/Link Quality/{split($2,a,"=|/");print int((a[2]/a[3])*100)}')

This command works if I enter it at the command line. However, in the script file it does not work or at least it doesn't seem to. I can put echo $lnk right after and it returns nothing. The real kicker is, this was working before, but I changed distributions from Mint to MX Linux. I don't know how much that would affect anything but it's the only change I've made before this stopped working.

The other thing is, I also use a very similar script that was based on this one for battery level. It works great. But I can't understand why this one all of a sudden doesn't work anymore.

UPDATE - While I haven't yet figured out what was wrong, I did find a work-around. Instead of using a .sh file to get the information I wanted and manipulating it from there, I just decided to do it directly in the conky template. There's always more than one way to get the desired output.

Thanks anyway for what it's worth.

  • 1
    Are you sure your wireless interface name is mlan0? Sep 25, 2019 at 21:29
  • 1
    Yes I am 100% certain that is the interface name. There are other functions that list other statistics from the interface and they use the same device name and work fine. @RuiFRibeiro, apologies for the title. I should have made it more relevant to the topic.
    – Swerved
    Sep 25, 2019 at 23:07
  • You write that you use a .sh file. Are you sure it is executed in /bin/sh, and not in bash, for example? Oct 2, 2019 at 5:30

1 Answer 1


Does classic Bourne shell's backtick-based construct work?

Like following script...

LINK_Q="`iwconfig mlan0 | awk '/Link Quality/{split($2,a,"=|/");print int((a[2]/a[3])*100)}')`"
echo "$LINK_Q"

If it doesn't, do you have a way to know which exact brand and version of shell that Conky used for running the script?

P.S. If you changed GNU/Linux distribution, also double-check the interface name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .