주어진 x 번호의 제곱근을 찾기 위해이 코드를 작성했지만 마지막 부분에서 "정수 표현식이 필요합니다"라고 알려줍니다. 어떻게해야합니까? (저는 쉘/bash 멍청이입니다)숫자의 제곱근을 찾는 Bash 스크립트 (바빌론 방법)
#bin/bash
2 clear
3 echo "Hello, we will calculate the square root of a number x"
4 echo "We're going to use the Babylonian Method"
5 echo "Give me a valor for x"
6 read x
7 if [ $x -lt 0 ]
8 then
9 clear
10 echo "The roots of this number are imaginary"
11 elif [ $x -eq 0 ]
12 then
13 clear
14 echo "The square root of 0 is 0"
15 else
16 echo "Now give me a base b and a vertical height h so that bh=x"
17
18 echo "Give me b"
19 read b
20 echo "Give me h"
21 read h
22 fi
23
24 if [ $b -eq $h ]
25 then
26 echo:"b or h are already the square root of h"
27 else
28 until [ $b -eq $h ]
29 do
30 b=`echo "scale=3; ($b + $h)/2"|bc -l`
31 h=`echo "scale=3; $x/$b"|bc -l`
32 done
33 fi
34 echo "the square root of x is $b or $h"
35
http://unix.stackexchange.com/q/155551/74329 – Cyrus