Hypotenuse From Shell Script Linux -
this related previous question: making shapes linux shell script
i'm trying write shell script program vim given sides , b of pythagorean theorem, provide c. here code:
echo -n "enter a: " read echo -n "enter b: " read b bsquared=$(($b**2)) asquared=$((a**2)) csquared=$(($b+$a)) hypot='echo"scale=2;sqrt($csquared)"|bc' echo ' + |\ | \ c | \ | \ +---- b ' echo "a = $a" echo "b = $b" echo "c = $hypot"
the triangle part fun. thing wrong script on line:
echo "c = $hypot"
the output follows:
c = "scale=2;sqrt($csquared)"|bc
in other words, code script. can tell me i'm doing wrong?
for command substitution, must use backticks or $()
syntax, not single quotes.
you must separate echo
command argument adding space after it.
replace:
hypot='echo"scale=2;sqrt($csquared)"|bc'
with:
hypot=`echo "scale=2;sqrt($csquared)"|bc`
or better readability :
hypot=$(echo "scale=2;sqrt($csquared)"|bc)
Comments
Post a Comment