delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/09/06/08:46:38

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Thu, 6 Sep 2001 07:45:38 -0500
From: Wayne Willcox <wayne AT reliant DOT knighthammer DOT com>
To: "Fritz, Wolfgang" <Wolfgang DOT Fritz AT datentechnik DOT com>
Cc: cygwin AT cygwin DOT com
Subject: Re: "if" "then" "elif" "fi" "done"
Message-ID: <20010906074538.A23957@reliant.immure.com>
Reply-To: Wayne Willcox <wayne AT reliant DOT immure DOT com>
References: <C287DEEDF2D4C1409FDE10D8253BD700C1B1 AT eurobird DOT dt DOT net>
Mime-Version: 1.0
X-Mailer: Mutt 1.0pre2i
In-Reply-To: <C287DEEDF2D4C1409FDE10D8253BD700C1B1@eurobird.dt.net>
X-Operating-System: FreeBSD reliant.knighthammer.com 3.5-STABLE FreeBSD 3.5-STABLE

Also you must include white space between the [ and the items under
test.
correct:
	if [ $one -eq 1 ];then
incorrect:
	if [$one -eq 1];then

On Thu, Sep 06, 2001 at 08:36:36AM +0200, Fritz, Wolfgang wrote:
> 
> 
> > -----Original Message-----
> > From: Harter, Pete [mailto:Pete DOT Harter AT itt DOT com]
> > Sent: Thursday, September 06, 2001 8:02 AM
> > To: 'cygwin AT cygwin DOT com'
> > Subject: "if" "then" "elif" "fi" "done"
> > 
> > 
> > Dear Cygwin:
> > 
> > I'm using Cygwin on NT, writing a bash script to catenate 241 files
> > together.  I can't seem to get the  "elif" "fi" "done" 
> > statements to work.
> > Using "then" seem to have no effect.
> > 
> > In particular, "elif","fi","done" all cause syntax errors.  
> > I've done a "man
> > bash", which tells me that the "fi", "elif", "done", etc. 
> > ought to work.  I
> > can't find much on the www.cygwin.com about syntax.
> 
> That's because this is not a cygwin specific problem. Try to find a
> standard book about shell programming. 
> 
> The "if" problem:
> "if, elif" needs a "then"
> 
> if condition ; then
>    do_something
> elif other_condition ; then
>    do_other_things
> fi
> 
> You may place "then" on a seperate line:
> if condition
> then
>   do_something
> fi
> 
> A special trap with "["
> 
> if [ $i -gt 5 ] ; then
> #   ^ this blank is a must
> 
> reason: "[" is an alias name for the command "test", the above really
> means:
> 
> if test $i -gt 5 ; then
> ...
> fi
> 
> do a "man test" to find the differences between "-gt" and ">" etc.
> 
> Wolfgang (hoping the M$ outlook does not mangle the formatting too
> much...)
> 
> > 
> > Here's my commands: 
> > 
> > #!/bin/bash -x
> > pdt="/cygdrive/e/temps"
> > pcase="case2"
> > #
> > cat $pdt/$pcase/$pcase'001'.bdf > $pdt/$pcase.temp
> > pi=2
> > while [$pi < 241]
> > do
> >   if [$pi < 10] 
> >     cat $pdt/$pcase/$pcase'00'$pi.bdf >> $pdt/$pcase.temp
> >   elif 
> >     if [$pi < 100] 
> >       cat $pdt/$pcase/$pcase'0'$pi.bdf >> $pdt/$pcase.temp
> >     elif [$pi >= 100] 
> >       cat $pdt/$pcase/$pcase$pi.bdf >> $pdt/$pcase.temp
> >     fi
> >   fi
> >   echo $pi
> >   pi=$pi+1
> > done
> > 
> > I revised the commands (by trial & error) to the following, 
> > which gives no
> > syntax error except that it says "unexpected end of file" 
> > after the last
> > line:
> > 
> > #!/bin/bash -x
> > pdt="/cygdrive/e/temps"
> > pcase="case2"
> > #
> > cat $pdt/$pcase/$pcase'001'.bdf > $pdt/$pcase.temp
> > pi=2
> > while [$pi < 241]
> > do
> >   if [$pi < 10] 
> >     cat $pdt/$pcase/$pcase'00'$pi.bdf >> $pdt/$pcase.temp
> >   ei 
> >     if [$pi < 100] 
> >       cat $pdt/$pcase/$pcase'0'$pi.bdf >> $pdt/$pcase.temp
> >     ei [$pi >= 100] 
> >       cat $pdt/$pcase/$pcase$pi.bdf >> $pdt/$pcase.temp
> >     endif
> >   endif
> >   echo $pi
> >   pi=$pi+1
> > enddo
> > 
> > Please help.  Thanks
> > 
> > Pete Harter
> > ITT A/CD Mechanical Analysis
> > 219-451-6865
> > <mailto:pete DOT harter AT itt DOT com>
> > 
> > 
> > --
> > Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> > Bug reporting:         http://cygwin.com/bugs.html
> > Documentation:         http://cygwin.com/docs.html
> > FAQ:                   http://cygwin.com/faq/
> > 
> > 
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/

-- 
Slowly and surely the unix crept up on the Nintendo user ...
Wayne Willcox                          I will not eat green eggs and ham
wayne AT reliant DOT immure DOT com                     I will not eat them Sam I Am!!
A wise person makes his own decisions, a weak one obeys public opinion.
                -- Chinese proverb

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019