LinuxQuestions.org
Register a domain and help support LQ
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 12-10-2009, 02:08 AM   #1
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
How to supress error messages


Some statements will give some error messages certain times. For example
Code:
a=$(($n%10))
will give an error message if n is a non integer. Under these conditions how can I carry on with my code by suppressing those error messages?
 
Old 12-10-2009, 02:21 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
AFAIK it is not possible (for good reasons) so the solution is to sanity-check variable values before using them in a way that might cause problems. What do you want your program to do if $n is non-integer? If you want to do arithmetic on values that may be non-integer, the usual solution is to use bc.
 
Old 12-10-2009, 02:24 AM   #3
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by catkin View Post
AFAIK it is not possible (for good reasons) so the solution is to sanity-check variable values before using them in a way that might cause problems. What do you want your program to do if $n is non-integer? If you want to do arithmetic on values that may be non-integer, the usual solution is to use bc.
Actually, I am trying to do the reverse of a number through bash scripting. For integer values its working fine but for non integer values it's giving a error message.
 
Old 12-14-2009, 03:41 AM   #4
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
I think we can suppress the error messages as well as the warning messages by running the command as fallows:
"Command Sequence 2>filename". For Example:
Code:
$ cat filename 2>/dev/null
 
Old 12-14-2009, 04:59 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by ashok.g View Post
Actually, I am trying to do the reverse of a number through bash scripting. For integer values its working fine but for non integer values it's giving a error message.
Can you explain what you mean by "the reverse of a number"? You mean 12345 should become 54321?
 
Old 12-14-2009, 05:11 AM   #6
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by catkin View Post
Can you explain what you mean by "the reverse of a number"? You mean 12345 should become 54321?
Exactly......
 
  


Reply

Tags
error, messages


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 supress terminal output? RedOctober45 Linux - Software 2 01-11-2008 08:59 AM
Postfix: User messages are okay; but error messages themselves seem to be bouncing jgombos Linux - Server 3 03-03-2007 02:21 PM
Supress kernel output AP81 Linux - General 5 02-19-2007 02:16 AM
From where am i getting error messages to /var/log/messages? prabhuacsp Programming 3 02-16-2005 08:59 AM
From where am i getting error messages to /var/log/messages? prabhuacsp Linux - Networking 1 02-16-2005 12:34 AM


All times are GMT -5. The time now is 07:45 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration