Run testapp once with /opt/test/lib searched before the normal shared-library paths.
Do not change system-wide configuration or the linker cache.
Which command is appropriate?
A command-prefix assignment to LD_LIBRARY_PATH adds a directory only to that process environment; it does not change persistent configuration.
Detailed explanation
PATH=/opt/test/lib ./testappIncorrect. PATH is used to locate executable commands, not shared libraries.
Incorrect. PATH is used to locate executable commands, not shared libraries.
LIBRARY=/opt/test/lib ./testappIncorrect. LIBRARY is not the standard glibc search-path variable.
Incorrect. LIBRARY is not the standard glibc search-path variable.
ldconfig /opt/test/lib ./testappIncorrect. ldconfig is not invoked with an executable in this form and would alter cache-related state.
Incorrect. ldconfig is not invoked with an executable in this form and would alter cache-related state.
LD_LIBRARY_PATH=/opt/test/lib ./testappCorrect. LD_LIBRARY_PATH=/opt/test/lib ./testapp applies the search path to this execution only.
Correct. LD_LIBRARY_PATH=/opt/test/lib ./testapp applies the search path to this execution only.
Try it yourself
An example you can run in a temporary verification environment.
LD_LIBRARY_PATH=/opt/test/lib sh -c 'printf "%s\n" "$LD_LIBRARY_PATH"'Expected result
/opt/test/libKey points
- LD_LIBRARY_PATH is for dynamic libraries
- A command-prefix assignment is temporary
- Avoid using it as a permanent system setting
Notes
- Environment: Linux / POSIX shell・glibc dynamic linker
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.