LinuxQuestions.org
Help answer threads with 0 replies.
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, 02: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, 02:31 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,263

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
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, 02: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, 02:48 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,263

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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration