#!/bin/bash
if[$LD_PATH == ""]
then
export LD_PATH=$1
else
export LD_PATH=$LD_PATH
fi
#excute the program that needs the path
./someProgThatNeedsThePath
i keep getting “cannot open shared object file”
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, your bash syntax is broken due to lack of spaces. First, you would need spaces around the
[and]closures. If you use the newer alternate double bracket syntax, you don’t have to worry about quoting variables you are testing.But your real problem is not that at all. Since your code is running in a separate bash shell, the code will have no effect on anything you run in the parent shell. In order to do that you would want to build a function:
Add that code to your .profile, then run it with
add_to_ld_path /my/pathwhen you want to use it. Note that since your “else” statement wasn’t actually doing anything, I removed it. I also replaced your test for a blank string by making your own with quotes with the builtin empty string test.Next up is what you are actually trying to accomplish. If all you want to do is set the variable if it’s empty, UncleAli’s solution is very simple. But it might be useful to do something like this:
This would check the current path and add the path given if it wasn’t already part of the LD_PATH variable, otherwise it would leave it alone.