![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Print Error with set command | Shribigb | Shell Programming and Scripting | 0 | 03-06-2009 06:08 PM |
| tar error exit delayed form pervious error | chayato | Linux | 1 | 02-06-2009 12:07 AM |
| In ksh shell command - Print "-ABC" is giving error | sagarjani | Shell Programming and Scripting | 2 | 10-08-2008 04:32 PM |
| Custom error page when tomcat authentication fails | sebagra | UNIX and Linux Applications | 0 | 05-06-2008 05:10 PM |
| at command fails | a329743 | UNIX for Advanced & Expert Users | 1 | 10-05-2006 10:08 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
How to print error and exit if command fails?
Guys any tips on printing a certain error message to stderr and exiting should a command fail within a ksh script? I'm trying to null some output files.
Touch isn't suitable as i need to null them. print "" > file isn't suitable as i need to check elsehere for if they are 0bytes or not. I've tried these below examples and none work correctly. I don't want to have to put a check after each command as :- Code:
if [[ $? -ne 0 ]];then print "error blah blah" >&2 exit 2 fi Code:
OUTFILE=/tmp/out
# Null outfiles. Security already checked
> ${OUTFILE} || print "ERROR: blah blah \n" >&2 ; exit 2 #doesnt work
> ${OUTFILE} || (print "ERROR: blah blah \n" >&2 ; exit 2 ) #doesn't work
> ${OUTFILE} || (print "ERROR: blah blah \n" >&2 && exit 2) #doesnt work
if [[ -n "$(> ${OUTFILE} 2>&1)" ]];then
print "ERROR: blah blah \n" >&2
exit 2
fi # doesnt work
|
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|