LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-06-2015, 01:02 PM   #1
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Rep: Reputation: Disabled
sending a command output to a variable


The following line give me the last ID of radwatch process:

echo `ps aux | grep "[r]adwatch" | awk '{print $2}'` | grep -Eo "[1-9]+$"

now if I want use a variable and assign the same command, the varible will be empty!!

mystring=`ps aux | grep "[r]adwatch" | awk '{print $2}'` | grep -Eo "[1-9]+$"
echo "$mystring"

Any help will be appreciated.
 
Old 12-06-2015, 01:30 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Probably misplaced backticks.

*Also see 'pgrep' as in PID_RADWATCH=$(pgrep radwatch 2>/dev/null).
**Also also "mystring" isn't a proper (descriptive) name for a variable if you intend to use more than one.
***Also please do not ever post duplicate threads again.
 
1 members found this post helpful.
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
redirecting a Command output to a Variable Ahmadhr Linux - Software 2 11-05-2013 04:31 AM
save command output to variable rajachan Programming 4 01-18-2013 07:48 AM
[SOLVED] output of a tar command not sending to my E-Mail amario26 Linux - Newbie 3 05-05-2011 06:09 AM
Output a C variable with a shell command paliga Programming 4 07-20-2010 06:10 AM
passing command output to variable Infernal211283 Linux - Newbie 12 01-11-2006 05:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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