I'm checking a counter in a loop to determine if it's larger than some maximum, if specified in an optional parameter. Since it's optional, I can either default the maximum to a special value or to the maximum possible integer. The first option would require an extra check at each iteration, so I'd like to instead find out what is the maximum integer that will work with the -gt
Bourne Shell operation.
相关问题
- How to get the return code of a shell script in lu
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- “command not found” errors in expect script execut
- Python script using subprocess and xclip hangs if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- Why does popen() invoke a shell to execute a proce
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Launch interactive SSH bash session from PHP
- Generate disk usage graphs/charts with CLI only to
- How can I create a small IDLE-like Python Shell in
I'd stay clear of integer limits as they're non portable and problematic
Instead I'd just do as you suggest and do the extra comparison like:
On my system, the maximum integer of Bash seems to be the same as the LONG_MAX constant of my Perl POSIX library. Obviously, this will vary on your platform, and how your Bash was compiled, etc. But that seems to be a good starting point for testing it:
Update: After trying this on an old 32 bit Linux, I see that my Perl's POSIX LONG_MAX is 2147483647, but that Bash still has the same limit. It seems to be defined in /usr/include/limits.h, and to depend on your __WORDSIZE, which may be 64 bits even on 32 bit systems :
The Bourne shell has no facilities for storing or manipulating numbers - everything is stored as a string. If you are asking about this kind of thing:
then that is handled by a separate (in the Bourne shell) executable called
test
, which has a symbolic link called '['. So your question is really about the limits of thetest
command, which all the docs I can find seem quite reticent about.