bc -help

Note that running
which bc
gives back
/usr/bin/bc, whereas if it were a package
it would be /usr/local/bin/bc

You actually don't have to pipe things to it, though that's often what people do, but you can just type
bc and hit enter and it go to a new line, but with no prompt. You can then type whatever equation you want, like 2+2 and it will show 4.

I think, (not that I can read NapoleonWils0n's mind) that all that was meant is that it is included with a default FreeBSD install, that is, you don't have to install anything extra to have it running.

So, when you say it doesn't work, I wonder if you just typed bc hit enter and then got a blank. Into that blank line you can type your equation.

So, for example, and this is the same whether I'm using bash or sh. Copy/Pasted from my terminal.

$ bc 2+2 4 quit
If you've never used it, you might not realize that the blank line was where you could put your equation.
I use it in a bunch of simple scripts to convert metric, (which my wife uses) to Imperial. For example she'll ask the temperature, I'll check on wunderground.com, and it gives me say, 85 degrees. I run it
through a little script.
#!/bin/sh echo "Enter Farenheit temperature" read ftemp ctemp=$(echo "scale=1; ($ftemp - 32.0) * 5.0 / 9.0" |bc) echo $ctemp exit 0 .
You can make a bunch of scripts like that, to do kg to lbs, etc.
 
hruodr your stuff is probably a lot more complex than what I use it for. I had to check the man page for bc -l. :) I do use scale=2 or 3 sometimes but mostly, being in the US, I use for metric/imperial conversions back and forth.
 
-h, --help
Prints usage information.
$ bc -h
usage: bc [-chlv] [-e expression] [file ...]

Ok so I thought since they called it help it would be like info on how to use bc. But there they say prints usage info and that is what you get. So why didn't they call it -u??
Help is only help if it helps.
 
You still haven't said what went wrong. Although it was written for somewhat more complex questions, you might take a look at http://www.catb.org/~esr/faqs/smart-questions.html. If you're fairly new to this, it's sometimes hard to figure out what questions to ask to get helpful answers.

Why it's called help rather than usage is possibly a question to take up with the program's creators. It sounds as if you're somewhat new to FreeBSD. Usually what can be considered help is in the man pages. If you type man bc you'll see a far more detailed description of usage, but it seems as if you are looking for a basic bc tutorial. Not that I can read your mind, but it's what I'm guessing from your questions. The https://www.geeksforgeeks.org/bc-command-linux-examples/ page has some examples for using it that might be useful. But for us to help, you're going to have to be specific about what didn't work. Did you type bc, and nothing appeared? Or did you get a blank line after you hit enter? If so, did you try to put an equation in? These are the sort of things you'll have to let us know before we can give you more helpful answers.
 
-h, --help
Prints usage information.
$ bc -h
usage: bc [-chlv] [-e expression] [file ...]

Ok so I thought since they called it help it would be like info on how to use bc. But there they say prints usage info and that is what you get. So why didn't they call it -u??
Help is only help if it helps.
Welcome to the unix tradition. There is roughly 50 years of it.

Want to know how to use the command foo, what it does, the details of input and output, the options and arguments in detail? Try "man foo". Want to have concise usage information, such as a quick overview of what options exist, with 1-line descriptions, and what arguments are mandatory? Either run it with no arguments if some are required, or try the -h option.

Also, there is a (somewhat newer) tradition that there are short one-letter options, which use a single minus sign, and long (word or multi-word options) that use two minus signs. Note that not all commands stick to that tradition, so "foo help" and "foo -help" might all work. And also note that some large sets of Unix software (for example the Gnu tools) deliberately ignore certain parts of these traditions, for example by using "info foo" instead of "man foo".
 
Ok so I thought since they called it help it would be like info on how to use bc. But there they say prints usage info and that is what you get. So why didn't they call it -u??
Help is only help if it helps.
It does.

As a unix-user I neither don't know no "info", nor "-u"
"u" for what?
For "unless it's something completey different", "unix is not Linux", or "uh, I don't understand"?

What I do know is what all unix users know, what's written within the "where to get help"-section of any halfway usable introduction into unix:
Almost every CLI/shell-command provides two things:
man bc

bc -h

"h" is short for and mostly reserved for "help"
whereas additionally -help or --help may also be available.
Sometimes you have to try one or the other, but if the according piece of software is not a piece of junk but truely unix(like), at least one of those is always available.

On my installation all three work: bc -h, bc -help, bc --help
and they all do what 'help' does:
give a (brief, short) help;
an overview what version, what this piece of software is, and the most common options - mostly ment simply as an reminder for people who already know this software but just forgotten its usage or one of the main options.

And if help is done properly - and here bc's help is exemplary - it also contains a link to where to look for more detailed information, if help is not sufficient: its handbook, in english also known as the manual, short "man" (shell- aka unix-users like texts to be brief and short.)
Many help-texts spare themselves to mention there is a manpage, because
man ... is what every unix-user (should) know if grappled with unix longer than 10 minutes.
bc doesn't.
Quote from bc's help:
bc 6.2.4
Copyright (c) 2018-2023 Gavin D. Howard and contributors
Report bugs at: https://git.gavinhoward.com/gavin/bc

This is free software with ABSOLUTELY NO WARRANTY.

usage: bc [options] [file...]

bc is a command-line, arbitrary-precision calculator with a Turing-complete
language.For details, use `man bc` or see the online documentation at
https://git.gavinhoward.com/gavin/bc/src/tag/6.2.4/manuals/bc/A.1.md.
[...]


Of course, one needs to read until
"For details, use `man bc` or..."

So, if you open the man page of bc by
man bc
it provides you with what according to man man a manpage provides:
"display online manual documentation pages"
THE complete reference documentation on all unix(like) since 1969 (I may be wrong about the exact date; the first manpages may occured in the seventies, but that is not my point here.)

Manpages are the only way I can think of to have a complete but usable documentation of a still developed operating system that contains several thousands of things (A book would be extremely large - and outdated before it be even finished printing.)

Okay, there is one downside:
One needs not only to be capable of reading but also actually do the reading.
And most of them won't come with any pictures, videos or comic strips, but short and brief text, only.
But therefor it's all in there.

Most manpages also keep it brief and short; sometimes maybe a bit too short
(I 'love' those entries:
"-u option to activate u" (Really? I didn't thought about that. WTF DOES 'U' DO?!?!")

So you may look for something having more explaining text, like a How-To,
or, if you have too much time, a video listening to the text somebody else reads for you, which is way slower than reading yourself (if not, you do have a handicap about reading, which in almost all cases can be solved by reading.)

Anyway,
EVERYTHING you'll ever need (on a true unix[like] os) is somewhere written in some manpage.
Unless the according software is a useless piece of junk. Because that's exactly what it is if it lacks a sufficient, complete, correct and up-to-date man page: useless. It cannot be used, because without a proper documentation nobody except the programmer her- or himself knows how to. (That's something that in certain sloppy conspiracy circles is still rejected to be accepted, or not understood, while at the same time those don't understand why their magnificent piece of brilliant software made by genies is not the widely used standard, but more and more rejected aka dying.)
Many manpages contain something like:
"Any inconsistency in this manpage is considered a bug - please report!"
Very true.

Tipps:
Learn how to read manpages.
If you open one the first time, don't read it all,
but at least skim once through it to the end.
Especially the bottom sections often contain very useful informations,
not only examples of usage but furthermore links to other manpages/pieces of software, which might be what you're actually looking for, and if not enlarge your knowledge anyway.

You may also use the webpage of manpages:
FreeBSD man pages
or there are also some how-tos for how-to make the display of your man pages be colorful, less boring, more clearly structured - I just forgotten, how I do it, but it's no rocketscience to figure it out.

Another (very) good source also comes with your installation on your machine:
file:///usr/local/share/doc/
I have it set as a link in my browser.
It's a good idea simply to skim through it, take a closer peek to something interesting, or even read the one or the other piece of text, you'll find in there.
It's a goldmine!

In the end, unix(like) is much about learning how to help yourself.
Everybody in this forum is very willing to help.
But if someone seem to not have done even the slightest attempt of trying by her-/himself one risks to get answers like this one, or some others I read here. 😁

Don't be discouraged!
This is also part of the learning process to get into unix.
🤓

Short:
read
RTFM!
 
Back
Top