Question

I'm curious about the limitations of the let command in a shell; I've tried searching for information but unfortunately it's a very common word and it's a shell built-in so many man pages don't actually describe what it does.

I have however been using it a lot for basic arithmetic operations, but for larger values I'm concerned about whether let may have limitations that might result in issues later on. I know bc is intended to handle arbitrary precision values, and I prefer to use it if I know it's going to be available, but some platforms I'm working with don't have it. My inclination is to convert code feeding values into bc to instead use let, but how limited is it? For example, does it work in a specific width of integer, and is this platform specific? If relevant, I'd also like to know if let has any common non-standard features or variations, so I can avoid using these.

Basically what I'm hoping for in an answer is a summary of any limitations on values that let can work with, and what features of it are specific to platforms or architecture features that it runs upon.

Was it helpful?

Solution

Depending on how you define larger values, your concerns are valid.

Let does "fixed with" integer aritmethics with no overflow checking whatsoever, the "fixed width" is implementation/system dependent. I do not know if posix defines the a minimum "width". If I recall correctly, bash does the calculations using longs.

Note on protability; Korn, bash and POSIX compatible shells have let, older bourne shells do not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top