LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-01-2010, 06:54 PM   #1
0bfuscated
LQ Newbie
 
Registered: Jan 2010
Distribution: Debian / RH-CentOS / Fedora
Posts: 6

Rep: Reputation: 0
Counting the number of exit variables - Bash.


Is there a way to count the number of errors- an exit variable $? from one function?


precat1 ()
{
grep -i $CODE $TEST
if [ "$?" -eq "1" ]; then
echo "Warning, no response. 1" >> $MSG
mail -s"$SUB" "$TO" < $MSG
fi

grep -i $CODE $TEST
if [ "$?" -eq "1" ]; then
echo "Warning, no response. 1" >> $MSG
mail -s"$SUB" "$TO" < $MSG
fi

grep -i $CODE $TEST
if [ "$?" -eq "1" ]; then
echo "Warning, no response. 1" >> $MSG
mail -s"$SUB" "$TO" < $MSG
fi

grep -i $CODE $TEST
if [ "$?" -eq "1" ]; then
echo "Warning, no response. 1" >> $MSG
mail -s"$SUB" "$TO" < $MSG
fi

}

the output from the exit variable (either erroneous or correct (1) or (0)) is it possible to add the erroneous one ups?

-Thanks in Advance.
 
Old 07-01-2010, 07:40 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
You can use any exit integer exit code < 256. It is not limited to 0 or 1. You check the exit code in the caller code using $?

jlinkels
 
Old 07-01-2010, 08:52 PM   #3
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Code:
#/bin/bash
total=0
for n in 1 2 3 4 5; do
    false
    ((total += $?))
done
echo $total
The output is 5.
Is that what you mean?
 
Old 07-02-2010, 11:43 AM   #4
0bfuscated
LQ Newbie
 
Registered: Jan 2010
Distribution: Debian / RH-CentOS / Fedora
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by KenJackson View Post
Code:
#/bin/bash
total=0
for n in 1 2 3 4 5; do
    false
    ((total += $?))
done
echo $total
The output is 5.
Is that what you mean?
I did something similar:
TEST6=$(($TEST1 + $TEST2 + $TEST3 + $TEST4 + $TEST5))
if [ "5" -eq "$TEST6" ]; then
func2
else
exit 0
fi

I appreciate the replied. I had a typical blank-out moment worth posting about.

-Take Care!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Counting the number of cfiles in a project Ajit Gunge Linux - Newbie 1 06-15-2010 07:09 AM
Bash: Counting the number of character occurences in a variable basildon Linux - Newbie 3 09-22-2008 10:11 AM
Counting number of system reboots rbh123 Linux - Newbie 2 11-22-2007 03:28 AM
having probrems counting variables carl0ski Linux - General 2 01-30-2006 04:40 AM
counting number of files akin81 Linux - Newbie 6 03-25-2004 01:53 PM

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

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