|
Home > Archive > Unix Shell > November 2006 > printing stings in bc -- basic calculator
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
printing stings in bc -- basic calculator
|
|
| Robert Katz 2006-11-24, 7:19 pm |
| $ bc
### How do I print on one line
### interest = 7 percent
--
Regards,
---Robert
| |
| Robert Katz 2006-11-25, 1:31 am |
| Robert Katz wrote:
> $ bc
> ### How do I print on one line
> ### interest = 7 percent
>
Of course I left out the essential part. The only thing in bc that
knows about 7 is the variable x.
Also How do I print a newline after a string?
--
Regards,
---Robert
| |
| Kaz Kylheku 2006-11-25, 1:31 am |
| Robert Katz wrote:
> Robert Katz wrote:
>
> Of course I left out the essential part. The only thing in bc that
> knows about 7 is the variable x.
print "interest = ", x, " percent"
works nicely in GNU bc 1.06.
> Also How do I print a newline after a string?
The same version recognizes some of the C language character escapes
such as \n.
print "interest = ", x, " percent\n"
| |
| Robert Katz 2006-11-25, 1:16 pm |
| Kaz Kylheku wrote:
> Robert Katz wrote:
>
> print "interest = ", x, " percent"
>
> works nicely in GNU bc 1.06.
>
>
> The same version recognizes some of the C language character escapes
> such as \n.
>
> print "interest = ", x, " percent\n"
>
Thanks, Kaz, but regrettably I have to go this on a bc that does not
have the print extension.
--
Regards,
---Robert
| |
| Stephane CHAZELAS 2006-11-25, 1:16 pm |
| 2006-11-25, 14:55(+00), Robert Katz:
[...]
> Thanks, Kaz, but regrettably I have to go this on a bc that does not
> have the print extension.
I'm afraid there's no direct way, but you can do:
bc << E |
x = 7
"interest = "; x; " percent
"
E
paste -sd '\0'
or
bc << E |
x = 7
"interest = "; x; " percent@"
E
tr -d '\n' | tr @ '\n'
That is use "@" for newline.
Or use awk instead of bc.
--
Stéphane
| |
| Robert Katz 2006-11-25, 1:16 pm |
| Stephane CHAZELAS wrote:
> 2006-11-25, 14:55(+00), Robert Katz:
> [...]
>
> I'm afraid there's no direct way, but you can do:
>
> bc << E |
> x = 7
> "interest = "; x; " percent
> "
> E
> paste -sd '\0'
>
> or
>
> bc << E |
> x = 7
> "interest = "; x; " percent@"
> E
> tr -d '\n' | tr @ '\n'
>
> That is use "@" for newline.
>
> Or use awk instead of bc.
>
Thank you. What is the precision of each tool? That is, if you need
many significant digits accuracy, is either one of bc or awk
preferable to the other?
--
Regards,
---Robert
| |
| Stephane CHAZELAS 2006-11-25, 1:16 pm |
| 2006-11-25, 16:57(+00), Robert Katz:
[...]
> Thank you. What is the precision of each tool? That is, if you need
> many significant digits accuracy, is either one of bc or awk
> preferable to the other?
bc is arbitrary precision so has no limit. awk will generally
use the widest available float type available on your CPU/OS, I
think.
--
Stéphane
| |
| Bill Marcum 2006-11-25, 7:21 pm |
| On Sat, 25 Nov 2006 04:10:29 GMT, Robert Katz
<katz@hp.com> wrote:
> Robert Katz wrote:
>
> Of course I left out the essential part. The only thing in bc that
> knows about 7 is the variable x.
>
> Also How do I print a newline after a string?
>
print "interest = ",x," percent\n"
--
"One day I woke up and discovered that I was in love with tripe."
-- Tom Anderson
|
|
|
|
|