Sample Header Ad - 728x90

Use m4 interactively with bc

2 votes
1 answer
96 views
I would like to use m4 interactively as a preprocessor for bc. My immediate use case is to add an include capability to bc, but I can foresee other uses in the future. But there is a problem. Here is an example using bc on its own:
`
$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3+7
10
sqrt(12345)
111
quit
$
` And here is the same example using m4 interactively:
`
$ m4 -iP - | bc
3+7
10
sqrt(12345)
111
quit

$
` There are two differences. First, the m4 version suppresses the banner. Second, the m4 version doesn't execute quit immediately, but instead requires the enter key to be pressed an additional time before it executes the quit. Why do these things occur? How can I make the m4 version work the same way as the bc version?
Asked by user448810 (131 rep)
Apr 9, 2024, 08:03 PM
Last activity: Apr 12, 2024, 10:16 PM