Skip to content

Instantly share code, notes, and snippets.

@herd-the-cats
herd-the-cats / gist:6db11a190f694f94f4533d2ce8efe481
Last active September 7, 2020 23:06
Bash function creates a persistent subshell of bc to stream multiple arithmetic operations
# credit to https://github.com/F-Hauri/Connector-bash for the idea
function bcpipe() {
command -v bc 1>/dev/null 2>&1 || { printf "No bc binary.\n" 1>&2 ; return 1 ;}
[[ $# -lt 1 ]] && { printf "Usage: %s [BCSTART|BCSTOP] || \033[3mbc-compatible arithmetic arguments\033[0m\n" "${FUNCNAME[0]}" ; return 1 ;}
if [[ $1 == "BCSTART" ]] ; then
local tmpd
local tmpfifo
tmpd="$(mktemp -d)"