memory allocation to a variable

hello all..
i'm a beginner in shell scripting. I need to know what is really happening when we are creating a variable in shell scripting? how memory is allocated for that variable?

short answer: most shells have a resident variable memory pool, extending it requires a call to malloc(). Read the putenv manpage, it explains this.

What problem are you trying to solve? Out of memory?

1 Like

Mostly it doesn't matter because you don't have any access to shell internals. It just assigns space when needed.

How it works can differ from shell to shell, too. It doesn't have to do it any particular way, as long as it does the right thing when you do X=stuff.

What is good to keep in mind, though, is that there's usually a limit to the size of a shell variable. That limit can be can be as small as four kilobytes per variable on many systems.

1 Like

thank you.. someone asked me this doubt.. i'm trying to find an answer how it really works..