I just found out about piping stdout into Perl, and I was amazed that you could even do this:
[user@folder] $ echo print 1/3 | perl
0.33333[user@folder] $
From what I understand, you're putting the print command into Perl, and doing a floating point calculation using Perl's code. Please correct me. However, every time I do this, I get an answer that has no newline character. I've searched everywhere and I just can't keyword the terms specific enough to create the answer.
Here's a link to what I'm talking about, under poster Thor: How do I use floating-point division in bash?
He gave an amazing answer, but I couldn't comment or message the user, so I've decided to create a new question here.
I'm still trying to wrap my head around how this is working, variables as well.
$ three=3
$ echo $three/3 | perl
1[user@folder] $
Bonus question:
It started out as me just trying to get bash to output floating point numbers in arithmetic operations. I don't get why bc
can't return a float. Supposedly it can, but it just isn't working for me.
Ideally:
$ echo 1/3 | bc
0
$
should return .333 and not 0. I'm delegating to a tool, bc
, and bc
is supposed to be able to do floats. I just don't understand what's going on.