문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top