On 1/18/19 6:06 PM, Peng Yu wrote: > Hi, > > I see these global or static variables (1st column) used only by one > function (2nd column). Some are from bash, some are from the libraries > that bash depends.
OK. You've done the first part by compiling a list. Now you have to perform the analysis. > > It seems to be problematic to declare variables global/static but only > to use them in one function. Should these variables be made local? It's not problematic per se. You have to look at what the variables do. So start by eliminating 1) variables that are global because system libraries require them; 2) variables that are global because they are intended to be modified by applications and so are declared in public header files; 3) variables that reflect values set in user startup or config files, or correspond to flags or invocation options; 4) variables that you included incorrectly and are actually used in multiple files (e.g., this_shell_function, vi_insertion_keymap, dont_save_function_defs, from_return_trap, build_version, terminate_immediately, sh_syntabsiz, optflags, release_status, bash_copyright, bash_license, and so on). Then you have a manageable list that you can analyze. There probably are a few variables that aren't used anymore. A good optimizing compiler will remove those. There are also a few variables there for my use when debugging. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/