In shell programming, is there any way to find the variable and function addresses? Something like in c or c++ when we output the &x, we can get x memory address.
-
What would you want to do with that address? – sth Sep 24 '12 at 11:21
-
actually, i want to estimate the stack size at runtime,is there any way ? – user1694236 Sep 24 '12 at 11:27
-
Shell script doesn't have the concept of "addresses" or "memory" in general. So no, you can't get addresses of variables". – Some programmer dude Sep 24 '12 at 11:34
-
what a shame. thanks for you guys help – user1694236 Sep 24 '12 at 11:37
1 Answers
It depends on what you want. Most shells only support symbolic (or "soft") references, variables that contain the names of other variables. Korn shell 93 has name references, created using typeset -n
, but the address is not exposed. Take a look at that in man ksh
, it might help.
But even if you could get the memory address of variables, what would you do with it? Shell variables are not structured in a primitive manner as in C, so pointer arithemtic would be no use. You could not iterate through an array or character string just by incrementing an address. The best you could do is investigate the memory of that particular version of that particular shell.
Since the shells are mostly written in C, you could always compile the shell source with debug (-g
) and connect using a debugger. No idea what that would buy you though, so my question has to be: why?
Edit; from a comment I see you want the stack size - I'm pretty sure that shell variables will be allocated either on the heap or in the environment block.

- 42,728
- 8
- 80
- 84