The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2006
TheCrunge TheCrunge is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 30
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!
  #2 (permalink)  
Old 03-21-2006
buffoonix buffoonix is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 145
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0