LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-22-2012, 03:27 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
saving result of command in variable


saving the version of java in a variable

result=`java -version`;
echo $result;

the result of the command java -version is not copied to the result variable.
Can anyone please help me in saving the result java -version into variable result
 
Old 07-22-2012, 03:31 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,035

Rep: Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338
java prints version info to stderr. If you want to catch it you need to redirect it to stdout (or catch stderr directly).
try: result=`java -version 2>&1`
 
1 members found this post helpful.
Old 07-22-2012, 03:36 AM   #3
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
thanks a lot pan64 you saved my life..
 
Old 07-22-2012, 03:48 AM   #4
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,035

Rep: Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338Reputation: 1338
Glad to help you! Just do not forget to "add reputation" - if you want to say thanks....
 
  


Reply

Tags
bash scripting


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] shell scripts: storing result of a command into a variable newbiecolonopenparens Linux - Newbie 14 05-24-2012 07:08 PM
[SOLVED] BASH Script. Result of command input into variable bcyork Linux - Newbie 4 12-06-2011 01:57 PM
how to store result of wc -l command in variable? trynq Linux - Newbie 11 04-20-2011 08:49 AM
How do you pass an expect command result into a variable and then use it again? edomingox Programming 2 05-09-2010 02:51 AM
How to pass a result of exec command in perl to a variable??? HyperTrey Programming 3 05-23-2008 01:47 PM


All times are GMT -5. The time now is 08:38 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