![]() |
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 |
| red hat check error log | itik | Linux | 3 | 06-06-2008 02:55 PM |
| script to check error | ust | Shell Programming and Scripting | 2 | 12-10-2007 11:27 PM |
| Check error after delete files. | icemania | Shell Programming and Scripting | 2 | 07-24-2007 11:22 PM |
| Automated FTP to variable directory with error check | songtam | UNIX for Dummies Questions & Answers | 3 | 04-10-2006 09:57 AM |
| check sum error | cubicle^dweller | UNIX for Dummies Questions & Answers | 3 | 09-22-2003 08:23 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Error check
How would I go about an error check within a script. For example, if I have a script that I know might contain an error with a certain command, is there a way to give an alternate command if the first fails?
The best way I can explain it, is from the Mac world, using Applescript. With AS, I can do something this: try do something on error do something else end try Is there a similar function for shell scripting? Thanks! |
|
||||
|
Afaik, the shell interpreters don't offer exception handling
as you have quoted from AppleScript (but then I don't know AppleScript). You can however check a command's return code which is captured in the special variable $? An RC of 0 is considered successful execution, and the shell's logic constructs evaluate a "true" condition in that case, which is a bit confusing if you are comming from other programming languages. In Perl scripting you would mimic exception handling by putting "problematic" code in an eval block and querying the Perl special variable $@ after it. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|