How do you read STDOUT into variables in bash?

Since the network speeds are not integers, we need to supplement with other tools such as awk to process the numbers. Try:

ifstat -ni wlp7s0 | awk 'NR>2{if ($1+0<100 && $2+0<100) print "Network is slow."; else print "Network is fast."}'

Or, for those who like their commands spread over multiple lines:

ifstat -ni wlp7s0 | awk '
    NR>2{
        if ($1+0<100 && $2+0<100)
            print "Network is slow."
        else
            print "Network is fast."
    }'

How it works

The -n option is added to ifstat to suppress the periodic repeat of the header lines.

NR>2{...} tells awk to process the commands in curly braces only if the line number, NR, is greater than two. This has the effect of skipping over the header lines.

if ($1+0<100 && $2+0<100) tests whether both the first field, $, and the second field, $2, are less than 100. If they are, then print "Network is slow." is executed. If not, then print "Network is fast." is executed.


John1024 is right about floating point numbers, but we can just truncate the numbers. With plain bash:

n=0
LC_NUMERIC=C  ifstat -i $interface  \
| while read -r in out; do
  ((++n < 2)) && continue # skip the header
  if (( ${in%.*} < 100 && ${out%.*} < 100 )); then
    echo Network is slow.
  else
    echo Network is fast.
  fi
done