(Adapted from my answer to another question indicated.)
It is important to understand that the LD_PRELOAD variable does not have much value for the operating system or for the shell. It makes sense and effect - if it has them at all - only in combination with a dynamic linker. If the dynamic linker is not involved, then LD_PRELOAD is another variable in the environment. Similarly, if the dynamic linker does not recognize this variable (for example, on OS X).
It is also important to understand that when executing a command whose name corresponds to a file that is not in an executable format, but which contains a shebang string, the specified interpreter is executed even if it is the shell itself. If the interpreter is an ELF binary that uses the dynamic linker. On the other hand, if there is no shebang line, then bash executes the contents of the file in a subnet environment, which does not require a dynamic linker; instead, the shell is just plugs. Other shells may or may not do the same.
It is also important to recognize that there are executable formats other than ELF. You are unlikely to encounter such binary code in a modern ELF-based system, but you should not rule out the possibility.
Bottom line: There is no way to guarantee that this dynamic library will be preloaded in the process space of an arbitrary shell command executed via bash or another shell selected by the user. If you require such a library to be preloaded for any or any arbitrary command, you need to more strictly control the runtime, perhaps by providing a custom shell and, possibly, also a custom dynamic linker and preventing others from being used.
source share