在我的.zshrc
文件中,我有以下一行:
export LD_LIBRARY_PATH='~/.local/lib'
我可以通过从命令行回显变量来确认变量已正确设置:
> echo $LD_LIBRARY_PATH
~/.local/lib
我有一个程序需要在本地lib目录中找到的库foo.so.1
。直接从命令行运行失败:
> bar -v 123
bar: error when loading shared libraries: foo.so.1: cannot open shared object file: No such file or directory
但是,如果在运行命令之前手动设置LD_LIBRARY_PATH,一切正常:
> LD_LIBRARY_PATH=~/.local/lib bar -v 123
Success!
我的问题是:为什么在运行命令工作之前立即设置变量,而在.zshrc
中设置它会失败?
答案 0 :(得分:1)
Please ensure your env variable gets assigned the path with "~" being expanded to your home directory as such expansion will not take place when the variable is being read.
Your (revised) code uses single quotes. Those will prevent expansion from taking place.