|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Redirecting errors of test command
Hello, Unix-Board! Normally, I would hide error messages in a shell script with Code:
command 2> path but test also prints out errors if I do that. The code of the script is (please don't tell me about bad coding ):Code:
echo "Enter a number here" read number test $number -ge 0 && echo "Thank you" && sleep 1 && exit test $number -le 0 && echo "Thank you" && sleep 1 && exit || echo "This is not a number" With this, I test if somebody entered a letter. Test does that well but it also prints out "illegal number [ letter i typed ]" and then displays the expected message. Where do I have to place the 2> to supress this? Thanks in advance, intelinside Last edited by fpmurphy; 04-13-2012 at 02:34 PM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Sorry, but you cannot redirect a syntax error. A numeric test expects a number. Also beware that you script had something after
exit which was not going to execute. First eliminate the non-numeric response. In this technique we try deleting all the numbers in the response and see if there is anything left (which would mean the answer was non-numeric). ( if -z is the same as test -z but modern convention). Code:
echo "Enter a number here"
read number
if [ -z "`echo $number | tr -d [0-9]`" ]
then
echo "Thank you"
sleep 1
else
echo "This is not a number"
sleep 1
exit
fi
# Continue processing $number here
# The next line is the last line
exit |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Okay, I read some man pages about the Code:
tr -d command you use in your script and I think it is is exactly what I need. Thank you! Last edited by intelinside; 04-14-2012 at 07:22 AM.. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help redirecting output to a file including errors | mbak | Shell Programming and Scripting | 10 | 10-09-2011 04:44 PM |
| Redirecting command output as well as commands | AncientCoder | Shell Programming and Scripting | 4 | 07-29-2010 10:51 AM |
| redirecting to stdout in betwen command | phoenix_nebula | Shell Programming and Scripting | 4 | 03-16-2010 01:09 AM |
| Redirecting output of a command to a file | ankitgoel | Shell Programming and Scripting | 3 | 04-13-2009 04:45 PM |
| redirecting output, including errors | kymberm | UNIX for Dummies Questions & Answers | 1 | 09-18-2002 12:59 PM |
|
|