LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 11-23-2015, 05:48 PM   #1
Alvin88
LQ Newbie
 
Registered: Mar 2012
Posts: 18

Rep: Reputation: Disabled
PIPESTATUS and EVAL - how to marry both?


Here is my question - maybe you can give me some idea about solving it:

I got commands like:
COMMAND="egrep test /tmp/alvin 2>&1 | tee /tmp/logfile ; RESULT=${PIPESTATUS[0]}";
output=$(eval $COMMAND);

How can get the exit code of the egrep command (as 0 is success or <>0 - error) to variable RESULT (and/or output) and use it in the rest of my script?

I know it is quite tricky with eval and PIPESTATUS, but maybe there is a way to do this?

Run out of ideas for the moment - can you help me out?

Last edited by Alvin88; 11-23-2015 at 05:51 PM. Reason: correction
 
Old 11-23-2015, 08:07 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am not sure I understand what you are trying to do? Why does the COMMAND variable need to be in the mix at all? Can't you just run the command normally and then use PIPESTATUS or RESULT variables
as required??

Personally I try to avoid eval wherever possible.
 
  


Reply

Tags
script



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
centos init.d script PIPESTATUS gillecaluim Linux - Newbie 1 10-10-2014 12:18 PM
understanding $PIPESTATUS Garrett85 Programming 3 10-31-2012 10:16 AM
[SOLVED] Bash Shell - PIPESTATUS mrm5102 Linux - Newbie 3 04-07-2011 08:40 AM
Marry Christmas to all LQ friends raju.mopidevi General 5 12-26-2009 10:26 AM
Would you marry me, VIM??? melinda_sayang Linux - Software 5 04-26-2004 02:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:11 AM.

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