I am learning shell scripts, I am trying to write a small script that adds and multi-digit number as shown below. But the value is not displayed
value=212 amt=`expr "( $value * 2 + ( $value * 2 * .075 ) ) " | bc` echo $amt
Your given code works fine, but I intend to suggest some improvements:
$(...)
expr
echo
Example:
value=212 amt=$(echo "( $value * 2 + ( $value * 2 * .075 ) ) " | bc) echo $amt
Output:
455.800
First of all. It:
value * 2 + (value * 2 * .075)
is a hot mess, this is equivalent to:
value * 43 / 20
Next, I prefer to use awk for this task:
#!/usr/bin/awk -f BEGIN { value = 212 print value * 43 / 20 }