Shell variable - limited size?

Are shell variables limited in size? And what is the maximum size a variable can contain?

+7
shell
source share
1 answer

Yes, they can be. It depends on your OS and / or on the shell and shell versions. It is safer to use temporary files if you expect variable values ​​to exceed 1-4 KB.

EDIT

Also see What is the maximum size of an environment variable? ; this concerns the OS restriction on the total environ size (the cumulative size of all VARIABLE=VALUE s), which affects the export ed variables, but the shell itself may have its own re restrictions. all (including non- export ed) variable sizes.

Speaking of which, if you do not have mobility, GNU bash relatively good in that it does not limit (not export ed) the size of variables and can very likely store arbitrary amounts of data until malloc can find enough memory and an adjacent address space . :)

+8
source share

All Articles