如何在shell脚本中放置正方形

时间:2014-11-28 07:41:49

标签: shell scripting

我已经为三角形识别编写了一些代码,但是无法为直角三角形编写代码。

#!/bin/sh
echo "enter the value of a"
read a
echo "enter the value of b"
read b
echo "enter the value of c"
read c
if [ $c = $a = $b ]
then
echo "Its a equilateral triangle"
fi
if [ $c != $a != $b ]
then
echo "Its a Triangle"
fi

2 个答案:

答案 0 :(得分:2)

if [ ($a*$a) + ($b*$b) = ($c*$c) ]
then
echo "right angle in triangle"
fi

答案 1 :(得分:0)

使用

#!/bin/bash
echo "enter the value of a"
read a
echo "enter the value of b"
read b
echo "enter the value of c"
read c

if ((c == a && c == b )); then
    echo "Its a equilateral triangle"
    exit 0
fi

if ((c != a || c != b )); then
    echo "Its a Triangle"
fi

请参阅http://wiki.bash-hackers.org/syntax/arith_expr