简体   繁体   中英

Convert BASH script to SH script [duplicate]

I am need to convert BASH script to SH:

#!/bin/bash
upper_limit=1500
lower_limit=1
middle=750
while [[ $lower_limit != $middle ]]
do
ping -M do -s $middle -c 1 8.8.8.8 &> /dev/null
if [ $? == "0" ]
then
lower_limit=$middle
else
upper_limit=$middle
fi
middle=$(( ($upper_limit + $lower_limit) / 2 ))
done
echo $middle

When i am just change to #!/bin/sh i have an error:

./test.sh: 6: [[: not found

I can't understand, what is wrong. Thanks for help.

This might be what you want (I'm sticking to your style)

upper_limit=1500
lower_limit=1
middle=750
while ! [ $lower_limit = $middle ]
do
ping -M do -s $middle -c 1 8.8.8.8 > /dev/null 2>&1
if [ $? = "0" ]
then
lower_limit=$middle
else
upper_limit=$middle
fi
middle=$(( ($upper_limit + $lower_limit) / 2 ))
done
echo $middle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM