how to goto in ksh | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

how to goto in ksh

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-11-2004
Geraldine Geraldine is offline
Registered User
 
Join Date: Mar 2004
Last Activity: 16 March 2004, 1:03 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
how to goto in ksh

Hi,
I'm trying to use the goto in ksh but it does not appear to be a valid command. Is that only valid in csh? Anything similar in ksh that I can use?

Appreciate any help you can provide.

Thanks.

geraldine
Sponsored Links
    #2  
Old 03-11-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 24 April 2014, 7:11 PM EDT
Location: Ashburn, Virginia
Posts: 9,839
Thanks: 42
Thanked 383 Times in 228 Posts
No goto in ksh. You will need to use structured programming.
Sponsored Links
    #3  
Old 03-11-2004
Geraldine Geraldine is offline
Registered User
 
Join Date: Mar 2004
Last Activity: 16 March 2004, 1:03 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
can someone shed some light on how I can write my own goto statement. I know it's generally not a good idea to use goto but in this circumstances, I think goto would be efficient.

I have a driver script (driverjob.sh) that calls several jobs, eg.

job1
job2
job3
job4
job5

if job3 fails, the driver script will write the name of the job to a log file and stop executing. After the error in job3 is fixed, if I rerun driverjob.sh, I would like the driver script to read from the log file the name of the failed job and process job3 onwards, thus bypassing job1 and job2.
If there is no goto command, the only way I can think of is to use if then else statement and check the status of each job.

Any suggestions?

thanks.

geraldine
    #4  
Old 03-11-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 24 April 2014, 7:11 PM EDT
Location: Ashburn, Virginia
Posts: 9,839
Thanks: 42
Thanked 383 Times in 228 Posts
Try something like:
Code:
[[ -f $LOGFILE ]] && read lastjob <$LOGFILE
for xjob in job1 job2 job3 job4 job5 job6 ; do
       if [[ -z $lastjob || $lastjob = $xjob ]] ; then
            ./$xjob || {echo $xjob > $LOGFILE ; exit 1 ; }
       fi
done

Sponsored Links
    #5  
Old 03-12-2004
Geraldine Geraldine is offline
Registered User
 
Join Date: Mar 2004
Last Activity: 16 March 2004, 1:03 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks! That works. I just had to make slight modification to your original script.

thanks again.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using A Goto Label? Grizzly Shell Programming and Scripting 5 09-12-2009 08:56 AM
How to goto end of the file s_linux Ubuntu 7 09-18-2008 02:12 AM
Goto last visted directory prasanth_babu Solaris 6 08-11-2008 03:17 AM
Stuck after typing goto rairey UNIX for Dummies Questions & Answers 2 09-20-2007 01:19 PM
goto statement Krrishv Shell Programming and Scripting 5 02-21-2007 06:36 AM



All times are GMT -4. The time now is 07:51 PM.