User: Password:
|
|
Subscribe / Log in / New account

Shell programming

Shell programming

Posted Dec 8, 2012 19:09 UTC (Sat) by Cyberax (✭ supporter ✭, #52523)
In reply to: Shell programming by nix
Parent article: Quotes of the week

>cyberax@cybmac:~$ factor 16
>bash: factor: команда не найдена [command not found]
Kinda fails.

Let's try "port search factor" - again it fails. There's no 'factor' utility in Mac OS X's ports.

On the other hand, Ruby version works perfectly even with the bundled Ruby interpreter.

And THAT is the problem with shells.


(Log in to post comments)

Shell programming

Posted Dec 8, 2012 20:01 UTC (Sat) by man_ls (guest, #15091) [Link]

I'd say that is a problem with the Mac OS X shell: it lacks the factor command.

Shell programming

Posted Dec 8, 2012 20:04 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link]

And Linux's shell lacks some SunOS's shell's tar options.

I've checked and it doesn't seem that the 'factor' command is mentioned anywhere in the POSIX spec.

Shell programming

Posted Dec 8, 2012 22:52 UTC (Sat) by man_ls (guest, #15091) [Link]

Neither does the POSIX spec mention ssh, rsync, wget, curl, less or a myriad of other commands in widespread use. Yet using them in scripts is easily forgiven; each command maintains excellent backwards compatibility on its own.

For your Mac OS X, I believe that brew install coreutils will get you a nice local copy of factor.

Shell programming

Posted Dec 8, 2012 23:26 UTC (Sat) by davidescott (guest, #58580) [Link]

What is this "less" you speak of? Maybe you are confused, the proper command is "more." Also what is this "ssh" do you mean "rsh?"

GNU has done an impressive job of unifying the *nix with a set of common tools, and the fact that someone can "brew install coreutils" and get a bunch of useful binaries is a testament to the value of the work GNU has done. BUT...

That does not mean that "shell" is the best language, it just means that shell is the least common denominator for interacting with a diverse set of programs (and it has served *nix well). Text input/output, flags for program options, silence is success, integer return codes, etc... As programs mature they get split into libraries, and those libraries get external interfaces to other languages like python/ruby/etc...

Shell programming

Posted Dec 8, 2012 23:10 UTC (Sat) by davidescott (guest, #58580) [Link]

I would go further and suggest that /usr/bin/factor is not something that should be in coreutils, and that OSX/BSD is far more sensible than GNU in excluding it. It just ends up polluting /usr/bin with functionality that would make more sense in a basic calculator like "bc" (which I curse out every time I start it because its so much easier to do basic arithmetic in python, ruby, R or octave).

If you look at what else is in coreutils factor seems completely out of place. There is not a single other tool in coreutils to do basic arithmetic. Where is there a /usr/bin/factor but not a /usr/bin/factorial, /usr/bin/exponent, /usr/bin/log or for that matter a /usr/bin/prime or /usr/bin/primes. In fact a good multi-function random tool (to generate random numbers or strings) would seem to be a far far far more useful thing to add to coreutils than "factor."

I'm really curious what considerations lead to "factor" being included into coreutils, is there an init script that really needs to factor a number before it can continue?

I don't mean this as a criticism of the developers of bc or coreutils or of GNU in general. Tools like "bc" were advanced and useful for their day. Thankful we have better alternatives for many use cases, and with 8 cores and 16GB of RAM I'm happy to waste a bit of each to get a more use friendly tool to do basic arithmetic and really don't need "bc" or "factor" anymore.

Shell programming

Posted Dec 9, 2012 17:39 UTC (Sun) by nix (subscriber, #2304) [Link]

I suspect only Roland McGrath can tell you why factor is in coreutils. It's been there since before it had an RCS repository (1992).


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds