Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-11-2008, 08:02 AM   #1
LQ Newbie
Registered: Oct 2007
Posts: 6

Rep: Reputation: 0
Check previous error status


This statement works if there is an error within the last command in
Line 01. I have to modify the code in Line 02 so that it checks for
errors in previous statements in Line 01. I want to get the error status
for previous commands in the statement in Line 01 such as the error
status for the command 'cat $ORA_LIST_FILE'. How to do it?

01 cat $ORA_LIST_FILE | wc -l 1> $ORA_LIST_COUNT_FILE_TMP 2>>
02 if [ ! $? -eq 0 ]; then
03 exit
04 fi
Old 02-11-2008, 09:25 AM   #2
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35

Even if you capture the output in an environment variable, you should be able to find the status in $?.

IMPOSSIBLE_TO_FIND_FILE=`ls this_file_is_not_here`

if [ $? -eq 0 ]; then
echo "Impossible file found."
echo "Impossible file not found."
Old 02-11-2008, 10:02 AM   #3
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 125Reputation: 125
The only return value available is that of the last command in a pipeline.
Old 02-11-2008, 11:07 AM   #4
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
Your problem should go away if you skip catting the file out. Just use wc.

Old 02-13-2008, 07:32 PM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,569

Rep: Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426
Indeed: 'useless use of cat', also, don't use
[[ ! $? -eq 0 ]]
[[ $? -ne 0 ]]

PS Matir is correct also


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
Installing RedHat 8.0 onto Dell PowerEdge SC1425 - hdc: status error: status = 0x58 fishsponge Linux - General 0 07-11-2006 10:02 AM
Check disk status diezjc Linux - Hardware 2 04-06-2006 04:58 PM
Hi Jeremy how do i check my previous post !! hitesh_linux LQ Suggestions & Feedback 8 12-18-2004 10:29 AM
Check for status of Serial ports in any language? BongFish Programming 11 09-11-2003 02:46 AM
Check Printer Status Debby Linux - General 5 02-08-2002 09:52 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration