LinuxQuestions.org
Register a domain and help support LQ
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 04-08-2006, 09:06 AM   #1
manish1380
LQ Newbie
 
Registered: Apr 2006
Posts: 2

Rep: Reputation: 0
Not clear about pipe's o/p


Hi ,

If I try a command that fails and pipe it to check the status of the last run command i get 0 always

eg :

echo abcd | grep mnop | echo $?

grep does not finds the pattern mnop but still echo $? gives 0.


Regards,
Manish
 
Old 04-08-2006, 09:34 AM   #2
chief_officer
Member
 
Registered: Mar 2006
Location: Istanbul, TR
Distribution: Red Hat, CentOS, Ubuntu
Posts: 180

Rep: Reputation: 30
Excuse me if I did not understand your post correctly. Suppose you have the following command:

command1 | command2

The logic behind the piping is to input the output of command1 as the input of command2. So, if command1 does not have any output, then command2 has no input.

Suppose you run exactly the following command:

cat somefile | grep text

If there is no somefile, then how can grep find text in a file that doesn't exist?

Reverse the question, what does echo $ give if grep finds the text you are searching?
 
Old 04-08-2006, 09:34 AM   #3
chief_officer
Member
 
Registered: Mar 2006
Location: Istanbul, TR
Distribution: Red Hat, CentOS, Ubuntu
Posts: 180

Rep: Reputation: 30
Excuse me if I did not understand your post correctly. Suppose you have the following command:

command1 | command2

The logic behind the piping is to input the output of command1 as the input of command2. So, if command1 does not have any output, then command2 has no input.

Suppose you run exactly the following command:

cat somefile | grep text

If there is no somefile, then how can grep find text in a file that doesn't exist?

Reverse the question, what does echo $ give if grep finds the text you are searching?
 
Old 04-08-2006, 11:25 AM   #4
manish1380
LQ Newbie
 
Registered: Apr 2006
Posts: 2

Original Poster
Rep: Reputation: 0
I am working on Red -Hat Linux.

the command
cat somefile | grep pattern | echo $?
gives:

0
cat: somefile: No such file or directory


what i mean is that even when somefile does not exist and so
obviously grep does not find anything

echo $? should give 1 as the previous command has failed but
irespective of that echo $? return 0.

Last edited by manish1380; 04-08-2006 at 11:38 AM.
 
Old 04-09-2006, 03:22 AM   #5
chief_officer
Member
 
Registered: Mar 2006
Location: Istanbul, TR
Distribution: Red Hat, CentOS, Ubuntu
Posts: 180

Rep: Reputation: 30
If you type

echo $?

without preceding pipe/redirection etc, then the output is 0.

So, I am tracking your question right, in your first post you have mentioned the following command:

echo abcd | grep mnop | echo $?

so the last command returns 0 irrespective of the previous pipe.

I think this is something to do with the options/parameters that you give to echo.
 
  


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
How to clear a std::string buff.clear()? lucky6969b Programming 3 03-17-2006 08:50 AM
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 06:02 PM
how do you clear the ... dailyd Linux - Software 3 02-26-2004 05:03 PM
Clear this please lramos85 Fedora 3 02-06-2004 07:35 PM
still not clear garorag Linux - Newbie 2 09-18-2001 01:48 PM


All times are GMT -5. The time now is 04:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration