¿Por qué cerrar una ventana de terminal y abrir una nueva a veces es la solución?

Sometimes when I'm debugging a program that runs from the command line, a seemingly obvious change doesn't work until I close the terminal window, open a new one, and try again. I've had this happen on both Mac OS (i.e., bash) and Windows.

This is a last-ditch thing I do when obvious solutions fail, but I'd like to know why. Is it something about the command-line program "capturing" a snapshot of something when it's created?

preguntado el 27 de agosto de 11 a las 17:08

I don't know for sure, but it could have to do with remembering which executable a command name refers to, e.g. if you've been using /usr/bin/foo y luego crear /usr/local/bin/foo, the shell might not see the latter. (though somehow I feel this isn't it). -

hash -r is a less drastic fix for that in Bash. -

1 Respuestas

Shells can hash known binaries (so they don't have to search the path for it)

When changing system wide environment variables, you need to start a new shell to get the new environment. Note that just entering a subshell doesn't work as child processes inherit their environments from their parents

Respondido 28 ago 11, 02:08

Can somebody expand on "Shells can hash known binaries"? I know what hashing is; is it somehow used when a command is about to be exeucted? - Gregg Williams

When changing system wide environment variables, you need to start a new shell to get the new environment. Okay, that is what I was thinking. Can anyone say more about el porqué you need to start a new shell? Is there a reason why the shell no puedes be aware of the current state of all environment variables? Thanks. - Gregg Williams

@Gregg: partly just by definition; UNIX has a long heritage like that. It's primary uses are security: prevent manipulation of environment to prevent compromising PATH/LIBPATH/LD_LIBRARY_PATH etc. that could be used to get untrusted code to execute. By extension, it serves to isolate processes: some processes will exigir a custom PATH etc. and they simply would not work correctly if child processes somehow started from 'the Un nuevo global environment' because they depend on the same environment as their parent(s) - sehe

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.