The shell case is simpler, but it has its characteristics.
#!/bin/sh
# scriptbc-wrapper for ' BC ' which returns the result of a calculation.
if [$ = ' P ']; Then
precision=$2
shift 2
else
precision=2 # default
fi
bc-q << EOF
scale=$ Precision
$*
quit
EOF
exit 0
Script Features:
1 The overall simplicity of the script, but powerful, can be implemented with custom numeric operations.
2 scale= $precision is passed to the BC parameters, to show the number of decimal digits
3) << EOF
scale= $precision $* quit
Eof
Used to pass a value to a script, similar to the effect of manually entering it under bash.
4) precision=$2 Shift 2 This line is interesting, and with this you can implement the function of scripting parameters,
Shift 2 means to move the input parameter left 2 bits, that is, $1,$2 first empty, the $ assignment to $1,$4 assigned to $.