Are shell variables limited in size? And which is the max size a variable can hold?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes they can be. It depends on your OS and/or the shell flavours and versions. It is safer to use temporary files if you expect variable values to exceed 1-4kB.
EDIT
Also see What is the maximum size of an environment variable value?; this deals with the OS limitation on total
environsize (cumulative size of allVARIABLE=VALUEs) which affectsexported variables, but the shell itself may have its own limitations re. all (including non-exported) variable sizes.This being said, unless you have portability in mind, GNU
bashis relatively good about not limiting (non-exported) variables’ sizes and can very likely hold arbitrary amounts of data as long asmalloccan find sufficient memory and contiguous address space. 🙂