Search code examples
bashparameterslimit

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


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.


Solution

  • 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: