3 ms·
> But soon after I discovered /proc/version, back in 1996, I realized that uname had no value. Wow, decades of experience in being a dolt? uname is in POSIX.
by kazinator 6y ago
> But soon after I discovered /proc/version, back in 1996, I realized that uname had no value.
Wow, decades of experience in being a dolt?
uname is in POSIX. It works all over the place. It's based on the uname library function, also standard.
M1 Mac:
kaz@minimac ~ % uname -a
Darwin minimac 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64
kaz@minimac ~ % uname -m
arm64
kaz@minimac ~ % cat /proc/version
cat: /proc/version: No such file or directory
arch is useless only because it's not in POSIX; scripts should probably be using uname -m when they want arch.
Them -m option is very useful, because if you are after "arm64" there is no way you should be writing shell script code to extract it out of the "uname -a" or /proc/version output.
/proc/version could deceive you, even if you're on Linux. Suppose you're in a chrooted cross-compilation environment, like an ARM QEMU environment on an Intel x86_64 machine. In that sandbox, you want *uname -m" to report arm, not Intel.
But if you mount the /proc filesystem into it, I think it will be the host one kernel one with no translation for /proc/version or other telltale entries.
A script that accesses /proc/version could be hostile to cross-compiling in an emulated chroot.
That's just something that occurs to be due to stuff I have learned since 1996.
Now let's talk bc: one reason that is useful because it has bignum arithmetic. And it is specified by POSIX, which spells out this feature in the very name:
bc - arbitrary-precision arithmetic language
Let's see:
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'.
2 ^ 300
20370359763344860862684456884093781610514683936659362506361404493543\
81299763336706183397376
Shell arithmetic cannot do it. Here is bash:
$ echo $((2 ** 3))
8
$ echo $((2 ** 300))
0
GNU Awk can do it today, if its compiled with GNU GMP, and invoked with the -M option. POSIX requires no such thing from awk.
When I was taking a number theory course in 1994, I used bc for some of the studying and homework due to the bignum
support. Today I'd use Lisp; but that's not a commonly installed utility you can count on to be there in a random Unix-like system.
bc doesn't do rational numbers, but it does scaled arithmetic. This is useful for money.
scale = 2
1.13 + 1.14 + 3.19
5.46
5.46 * 1.12
6.11
It can work in bases other than decimal and has a separate input/processing base (ibase register) and output base.