Artificial intelligent assistant

bash + arithmetic calculation with bash I need to do the follwing with bash what is the elegant way ? to get the final $sum value worker_machine=32 executors_per_node=3 executer=$worker_machine/$executors_per_node-1 spare=$executer X 0.07 sum=$executer-$spare ( with round the number to down ) example: 32/3 = 10 - 1 = 9 9 X 0.7 = 0.6 9 – 0.6 = 8 ( with round the number to down )

Using `awk`, taking values from shell variables:


awk -v n="$worker_machine" -v m="$executors_per_node" \
'BEGIN { printf("%d\
", 0.93 * (n / m - 1)) }' /dev/null


The `awk` script doesn't get any input as usual, so we use `/dev/null` as input file and do our calculation and output in a `BEGIN` block.

Using `bc`:


sum=$( printf '0.93 * (%d / %d - 1)\
' "$worker_machine" "$executors_per_node" | bc )
printf '%.0f\
' "$sum"


Using `dc`:


sum=$( printf '%d\
%d\
/\
1\
-\
0.93\
*\
p\
' "$worker_machine" "$executors_per_node" | dc )
printf '%.0f\
' "$sum"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 3c1d4cd251960927ab09655ffbdb1d29