Append to a pipe and pass on?

I achieved this using sed and replacing the end of the line:

echo "my text" | sed 's/$/ more text/'

Returns:

my text more text

Your example:

echo "750/12.5" | bc | sed 's/$/\/24/' | bc

In the simplest of the options, this does append to the pipe stream:

$ echo "750/12.5" | { bc; echo "/24"; }
60
/24

However that has an unexpected newline, to avoid that you need to either use tr:

$ echo "750/12.5" | { bc | tr -d '\n' ; echo "/24"; }
60/24

Or, given the fact that a command expansion removes trailing newlines:

$ printf '%s' $( echo "750/12.5" | bc ); echo "/24"
60/24

But probably, the correct way should be similar to:

$ echo "$(echo "750/12.5" | bc )/24"
60/24

Which, to be used in bc, could be written as this:

$ bc <<<"$(bc <<<"750/12.5")/24"
2

Which, to get a reasonable floating number precision should be something like:

$ bc <<<"scale=10;$(bc <<<"scale=5;750/12.5")/24"
2.5000000000

Note the need of two scale, as there are two instances of bc.

Of course, one instance of bc needs only one scale:

$ bc <<<"scale=5;750/12.5/24"

In fact, what you should be thinking about is in terms of an string:

$ a=$(echo "750/12.5")        # capture first string.
$ echo "$a/24" | bc           # extend the string
2

The comment about scale from above is still valid here.


Something like this seems to work using xargs:

$ echo "750/12.5" | bc |xargs -I{} echo "{}+20" |bc
80

Or even:

$ echo "750/12.5" | bc |echo "$(</dev/stdin)+20" |bc
80

And why not :

$ bc <<<20+$(bc <<<"750/12.5")
80