LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-02-2013, 06:25 AM   #1
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Rep: Reputation: Disabled
Unhappy shell script string manipulation problem :(


Dear sir,

i am trying to catch the path from the command and manipulate to use to go to that loaction
to understand better i am pasting my script

Code:
#!/bin/bash



OUTPUT=$(readlink -f $(which java))


cd $OUTPUT
this OUTPUT gives me string like
/usr/lib/jvm/java-6-openjdk/jre/bin/java

but this java is not a dir so it gives error
Code:
cd: /usr/lib/jvm/java-6-openjdk/jre/bin/java: Not a directory
i want to go to the location
Code:
/usr/lib/jvm/java-6-openjdk/
as i dont know so much of scripting please help me
please help me i want to get rid of this

Thanks & Regards
rohan
 
Old 07-02-2013, 06:43 AM   #2
Dr_P_Ross
Member
 
Registered: Nov 2003
Location: Edinburgh, UK
Distribution: Arch
Posts: 41

Rep: Reputation: 18
Instead of
Code:
  cd $OUTPUT
try
Code:
  cd `dirname $OUTPUT`
 
1 members found this post helpful.
Old 07-02-2013, 07:50 AM   #3
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by Dr_P_Ross View Post
Instead of
Code:
  cd $OUTPUT
try
Code:
  cd `dirname $OUTPUT`
Dear sir,

Thank you very very much for solving my issue n helping me in this

Regards
Rohan
 
Old 07-02-2013, 08:37 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,243
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Or to trim out jre/bin/java you could have:
Code:
cd "${OUTPUT%jre/bin/java}"
And a safer one would be:
Code:
DIR=${OUTPUT%java}; DIR=${DIR%jre/bin/}; cd "$DIR"
Some would also add more conditions, and some would have less usage or processing of variables but you get the idea.
 
2 members found this post helpful.
Old 07-02-2013, 09:05 AM   #5
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by konsolebox View Post
Or to trim out jre/bin/java you could have:
Code:
cd "${OUTPUT%jre/bin/java}"
And a safer one would be:
Code:
DIR=${OUTPUT%java}; DIR=${DIR%jre/bin/}; cd "$DIR"
Some would also add more conditions, and some would have less usage or processing of variables but you get the idea.
Dear sir,

Thanks for all ur rplyz

Regards
Rohaan
 
Old 07-02-2013, 09:28 AM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
Maybe another thing to consider is that is java is installed, this quite often goes hand in hand with the environment variable JAVA_HOME being created and set so could be used instead
of 'which java'
 
Old 07-15-2013, 07:28 AM   #7
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Question on Red hat linux having some problem in getting the readlink -f work

Dear sir,

i am using the

Code:
readlink -f $(which java)

to get the current active java on machine.

it gives output like


Code:
/usr/lib/jvm/java-6-openjdk/jre/bin/java
but when i try to use it in Red Hat (Red Hat Enterprise Linux Server release 5.4 )
its giving me output


Code:
/usr/bin/gij
location of binary

its not giving me location from jvm
how can i get it please let me know

Thanks,

Reagrds
rohan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] string manipulation in a script file mahmoodn Linux - General 12 06-02-2010 01:39 PM
Shell scripting problem: string manipulation Philip87 Linux - General 4 09-27-2008 01:29 PM
String manipulation with BASH script King V Programming 9 04-21-2006 03:15 PM
String manipulation with a script. philipina Programming 4 03-16-2004 02:42 PM
String manipulation with a script? philipina General 1 03-15-2004 12:07 PM


All times are GMT -5. The time now is 12:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration