Hi,
I wanted to know what is the maximum length of command which can be run on a bourne (sh) shell? Where can I find that information? Is it different for different OS flavors?
Please help.
Thanks,
Vineet
Hi,
I wanted to know what is the maximum length of command which can be run on a bourne (sh) shell? Where can I find that information? Is it different for different OS flavors?
Please help.
Thanks,
Vineet
#!/bin/ksh
# The value of the constant ARG_MAX defines how long an argument list your
# kernel can take on the command line before it chokes. Here's a script to
# find out the value of it:
# Print out the system's architecture
uname -rms # or uname -a
# Let the C preprocessor read in the system's limits from limits.h
# and then expand the macro ARG_MAX
# Filter out excess output (there will be some line number information
# and a gadzillion empty lines)
#
# On some gcc systems, I have been unable to find a working cpp.
# You can use gcc -E - <:<:HERE | tail -1 in that case.
cpp <<HERE | tail -1 # Only the last line is interesting
#include <limits.h>
ARG_MAX
HERE
You can also use getconf:
getconf ARG_MAX
I started chuckling when I read the cpp solution and half expected to see it followed by a "Why not 'grep ARG_MAX /usr/include/limits.h '?" post.
It's funny how sometimes we use the tools we are most used to - if we use a screwdriver every day, sometimes we'll use the handle end as a hammer.
However, "getconf" isn't always the right tool either because it doesn't necessarily have whatever it is you want. The man page explains what it will know about; and on recent Linuxes you can do "getconf -a". That can help when you aren't sure about whether or not to use a leading underscore or exactly what the constant is called - just
getconf -a | grep CPUTIME
, for example.
In particular,
getconf -a | grep MAX
can be educational and enlightening.
I agree,
most of the time I use grep limits.h ...
I use "man 5 limits".
$ man 5 limits
No entry for limits in section 5 of the manual
For my notes, which unix o/s doesn't have "man 5 limits"?
None of those I currently have access to:
Linux (Mandriva, Debian), FreeBSD, NetBSD
Thanks cfajohnson. I'd assumed that the standard implemention-specific "man 5" pages were pretty universal . After checking a generic Linux "man" site I see that most of the usual ones are present but not necessarily in the the same man section. No mention of "limits" though.
I'll take a closer look at a modern Linux and update my notes.
i just figure any script / command that actually needs to parse arguments any where near that limit is so poorly written that it'll fail eventually anyway...