Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add and Multiply numbers using shell script

Tags:

linux

shell

unix

I'm learning Shell scripting, I'm trying to write a small script that adds and multi number as shown below But amt value not display

value=212
amt=`expr "( $value * 2 + ( $value * 2 * .075 ) ) " | bc`
echo $amt
like image 712
Ban Avatar asked Jan 22 '26 00:01

Ban


1 Answers

Your code works fine, but I suggest some improvements:

  1. Use $(...) instead of backticks.
  2. Replace expr with echo.

Example:

value=212
amt=$(echo "( $value * 2 + ( $value * 2 * .075 ) ) " | bc)
echo $amt

Output:

455.800
like image 124
Jahid Avatar answered Jan 23 '26 13:01

Jahid