PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > How to skip one item in shell looping?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

How to skip one item in shell looping?

Réponse
 
LinkBack Outils de la discussion
Vieux 30/07/2007, 20h38   #1
Andrew Chen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to skip one item in shell looping?

Hi,
How to skip one item in a sh shell script?

for x in 1 2 3; do
if [ $x = "2" ]; then
#??? how to skip 2 and proceed to 3?
next ????
fi
done


Thanks
~Andrew Chen

  Réponse avec citation
Vieux 30/07/2007, 20h48   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to skip one item in shell looping?

On 2007-07-30, Andrew Chen wrote:
> Hi,
> How to skip one item in a sh shell script?
>
> for x in 1 2 3; do
> if [ $x = "2" ]; then
> #??? how to skip 2 and proceed to 3?
> next ????
> fi
> done


for x in 1 2 3; do
if [ "$x" = 2 ]; then
continue
fi
done


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 30/07/2007, 20h53   #3
Scott McMillan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to skip one item in shell looping?

On Mon, 30 Jul 2007 19:38:32 -0000, Andrew Chen <hangfei@gmail.com>
wrote:

>Hi,
>How to skip one item in a sh shell script?
>
>for x in 1 2 3; do
> if [ $x = "2" ]; then
> #??? how to skip 2 and proceed to 3?
> next ????
> fi
>done
>
>
>Thanks
>~Andrew Chen


You could use negative logic:

for x in 1 2 3
do
[ $x != 2 ] && {
Do Whatever With X
}
done

  Réponse avec citation
Vieux 31/07/2007, 00h17   #4
peter volsted
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to skip one item in shell looping?

hi

>Andrew Chen wrote:
> Hi,
> How to skip one item in a sh shell script?
>
> for x in 1 2 3; do
> if [ $x = "2" ]; then
> #??? how to skip 2 and proceed to 3?
> next ????
> fi
> done
>

for x in 1 3; do <whatever>; done


--
good luck

peter

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h21.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10038 seconds with 12 queries