0

This question already has an answer here:

I just stumbled over a script with works in bash but not in zsh:

if [ Darwin = `uname` ]; then
   library_path=DYLD_LIBRARY_PATH
else
   library_path=LD_LIBRARY_PATH
fi
if [ -z "${!library_path}" ]; then
   eval ${library_path}=${thisdir}/lib64:${thisdir}/lib; export ${library_path}
else
   eval ${library_path}=${thisdir}/lib64:${thisdir}/lib:${!library_path}; export ${library_path}
fi

the second if should apparently test, depending on the kernel, if $LD_LIBRARY_PATH is non zero, or if $DYLD_LIBRARY_PATH is non zero. And then either set or expand the respective variable.

How would I do the same in zsh? And is there a version that works in zsh and bash?

marked as duplicate by countermode, Anthon, HalosGhost, techraf, don_crissti Oct 24 '16 at 22:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

It appears $(eval echo \$\{$library_path\}) works:

if [ Darwin = `uname` ]; then
   library_path=DYLD_LIBRARY_PATH
else
   library_path=LD_LIBRARY_PATH
fi
if [ -z $(eval echo \$\{$library_path\}) ]; then
   eval ${library_path}=${thisdir}/lib64:${thisdir}/lib; export ${library_path}
else
   eval ${library_path}=${thisdir}/lib64:${thisdir}/lib:$(eval echo \$\{$library_path\}); export ${library_path}              
fi

though there might be a more elegant solution.

Not the answer you're looking for? Browse other questions tagged or ask your own question.