我有一个bash脚本,它运行这一行代码:
LD_LIBRARY_PATH=/tools/cluster/6.2/openbabel/2.3.2/lib ./xattr infile.txt outfile.txt如果我直接从shell调用这一行,它可以正常工作。但是,如果我在bash脚本中运行它,就会得到以下错误:
update.sh: line 45: LD_LIBRARY_PATH=/tools/cluster/6.2/openbabel/2.3.2/lib: No such file or directory为什么LD_LIBRARY_PATH在bash脚本中设置时不能工作?
下面是第45行的更多代码:
BASE_DIR="/volatile/huanlab/bold/kendal/bioinformatics_database/tmp"
COMP_DIR="$BASE_DIR/compound"
# move to the current directory where xattr.cpp and other files are
cd /users/kharland/software/programs/BioDB-update/dev
# Compile xattr ('make xattr' is the same command I call from the shell
# to compile this program when this program actually works).
make xattr
# loop over each .sdf file in COMP_DIR
for INF in $(ls $COMP_DIR | grep sdf)
do
babel -isdf $COMP_DIR/$INF -ocan $SMILES_DIR/$INF.csv
LD_LIBRARY_PATH=/tools/cluster/6.2/openbabel/2.3.2/lib ./xattr $COMP_DIR/$INF $COMP_DIR/$COMP_FILE
done这些行之前的内容只是注释。
编辑
在我的makefile中,我使用以下选项进行编译
LDLIBS=-lm -ldl -lz -lopenbabel
LDFLAGS=-Wl,-rpath,/tools/cluster/6.2/openbabel/2.3.2/lib:/tools/cluster/system/pkg/openbabel/openbabel-2.3.2/build/lib,-L/tools/cluster/6.2/openbabel/2.3.2/lib运行ldd xattr会显示库确实是链接的,所以程序在从shell调用时按预期执行。唯一的问题是bash脚本。如果我从bash脚本中删除LD_LIBRARY_PATH选项,就会遇到一个问题,即没有找到openbabel的共享库,尽管ldd显示xattr知道库在哪里。这就是为什么我在bash脚本中添加了LD_LIBRARY_PATH,我尝试使用它作为解决办法
编辑
(更正错误:将“库”与下面的“我的代码”交换)(下面有错误的文件系统名称)
我突然想到了一些事。我的源代码在/users文件系统中。如果我的库位于不同的挂载文件系统上,bash在查找这些文档时会有困难吗?
发布于 2014-06-29 16:11:23
设置环境变量确实适用于bash脚本。
试试这个:
#!/bin/bash
VAR1=VALUE1 env...run该脚本,您将看到包含VAR1及其值的输出。
一般来说,这也适用于LD_LIBRARY_PATH。
#!/bin/bash
tempdir=$(mktemp -t -d testdir.XXXXXX)
LD_LIBRARY_PATH=$tempdir env
rm -rf "$tempdir"如果您可以生成一个最小的复制器,而在这种情况下不会发生这种情况,那么这将是有帮助的和值得赞赏的。
https://stackoverflow.com/questions/24470946
复制相似问题