Home > Software design >  Is there a maximum number of characters that can be passed within one positional parameter in bash?
Is there a maximum number of characters that can be passed within one positional parameter in bash?

Time:01-14

I have a a variable which is a list (can have 10.000 characters) which I want to send as one positional parameter when calling some script. So I wonder is there a maximum number of characters that can be send this way?

The other option would be to save it in some file that will be read by this script, but from some reasons, first scenario may be easier for implementation.

It is RedHat OS.

Thanks.

CodePudding user response:

On modern linux, the maximum length of a single argument is MAX_ARG_STRLEN which is probably 131072 bytes:

/usr/include/linux/binfmts.h:

#define MAX_ARG_STRLEN (PAGE_SIZE * 32)

/usr/include/x86_64-linux-gnu/sys/user.h:

#define PAGE_SHIFT              12
#define PAGE_SIZE               (1UL << PAGE_SHIFT)

See also:

CodePudding user response:

There is a built-in limit to the operating system, on how much data can be passed to a child process. You can query this value from the command line using

getconf ARG_MAX

This value comprises the total length over all arguments plus the environment. There is no additional restriction for a single argument, but it means that if you have an unreasonably large environment, and want to pass many arguments to a process, this reduces the allowed size of a single argument.

  • Related