Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote this script to check if my dns server works fine or not, and if not change it. but it gives out error ./dns-ping.sh: line 15: ((: 3 < : syntax error: operand expected (error token is "< ")

where is the problem?

#! /bin/bash

echo "--------------------------------------------------------------"
echo "++ DNS Ping Tester ++"
echo "--------------------------------------------------------------"
echo "please enter threshold:"
read $threshold
for timer in {1..2}
        png=`ping -c 5 -q yahoo.com | grep -oP '\d+(?=% packet loss)'`
        let loss_count=$png+$loss_count
let loss_mid=loss_count/12
if (($loss_mid < $threshold)); then
#   ifdown eth0
    echo "less"
    echo "nameserver" > /etc/resolv.conf
share|improve this question
You want to replace < with -lt, which stands for "less than". – schaiba Apr 8 '13 at 15:25
Looks like you executed this script using sh rather than bash. – jordanm Apr 8 '13 at 15:34
@schaiba actually the < is perfectly valid bash when used inside (( )). – Patrick Apr 8 '13 at 15:39
up vote 1 down vote accepted

You have to replace the following line:

if (($loss_mid < $threshold)); then

By this one:

if [ "$loss_mid" -lt "$threshold" ]; then
share|improve this answer
now it gives this error: ./dns-ping.sh: line 15: [: : integer expression expected – Hojat Taheri Apr 8 '13 at 17:50
This modification works for me. $threshold has to be a numeric variable. – user36782 Apr 8 '13 at 18:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.