0

In a bash shell script on Ubuntu/Mint, I need to create some symlinks in the /jre/lib/ext/ directory under the java installation directory.

For example, if openjdk6 is the default java, /usr/bin/java points to:

/usr/lib/jvm/java-6-openjdk/jre/bin/java

I can find this in my script with:

MYJAVAPATH=readlink -f `which java`

The path I would need in my shell script would be based on part of that path, plus the path fragment above:

/usr/lib/jvm/java-6-openjdk/jre/lib/ext/

Can anyone tell me to to derive the path immediately above in a bash shell script? Thanks.

1
  • Could you just cd to that directory, back up to /jre/, then go into lib/ext ? Once there, then ln -s and get your symlinks in place? Commented Jan 30, 2012 at 0:08

2 Answers 2

4

You can simply append the relative part ../lib/ext/

MYJAVAPATH="$(readlink -f $(which java))"
LIB_EXT="$(dirname ${MYJAVAPATH})/../lib/ext"

and then use ${LIB_EXT}.

Sign up to request clarification or add additional context in comments.

2 Comments

That is a complete answer. Thanks. And other than doing this: cd $LIB_EXT; LIB_EXT=$(pwd), how can I get rid of the /../ path element?
also, I don't want to have to install any additional programs (such as realpath).
1

You could use dirname such as

javalink=`which java`
javapath=`readlink $javalink`
javadir=`dirname $javapath`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.