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
while loop inside while loop panknil Shell Programming and Scripting 0 01-07-2008 12:49 PM
sed in a for loop marwan UNIX for Dummies Questions & Answers 6 06-30-2007 05:41 PM
while loop help bobo UNIX for Dummies Questions & Answers 4 01-31-2007 05:56 AM
Endless loop - Fork function failed? cdunavent Shell Programming and Scripting 3 01-31-2002 01:12 AM
Menu function stuck in a loop? darthur UNIX for Dummies Questions & Answers 2 12-14-2001 04:16 PM

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 Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 06-16-2002
trynew trynew is offline
Registered User
  
 

Join Date: Jun 2002
Posts: 50
how to get the similar function in while loop or for loop

Dear all

How to write the shell script for the following statement:

(C programming)
for (i=0;i<30;i++) {
if i=1
continue *skip this number
(To do function here....)
...
}

similar statement in while loop....

I wrote the script in sh shell:

i=0
while [ $i -ng 30 ]
do
if [ $i -eq 1 ]
then continue
fi
(To do function here....)
i=$1+1
done


Unlucky, I can't get the correct result, can anyone help me?


Best regards
  #2 (permalink)  
Old 06-17-2002
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
Something like this should do it

#!/bin/sh
i=0
while [ $i -le 30 ]
do
case $i in
1) echo "skipped"
*) echo $i
esac

i = `expr $i + 1 `
done
  #3 (permalink)  
Old 06-17-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
You need semicolons to terminate the branches on the case:

1) echo "skipped" ;;
*) echo $i ;;
  #4 (permalink)  
Old 06-17-2002
trynew trynew is offline
Registered User
  
 

Join Date: Jun 2002
Posts: 50
Thanks for your replay and implementation!!!
Sponsored Links
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 11:48 PM.


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