public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Ralf Habacker" <Ralf.Habacker@freenet.de>
To: "Cygwin" <cygwin@sources.redhat.com>
Subject: AW: "if" "then" "elif" "fi" "done"
Date: Thu, 06 Sep 2001 02:25:00 -0000	[thread overview]
Message-ID: <000701c136b1$45efcfa0$651c440a@BRAMSCHE> (raw)
In-Reply-To: <C287DEEDF2D4C1409FDE10D8253BD700C1B1@eurobird.dt.net>

> >
> > 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.
>
the cygwin manpage of "test" doesn't say anything about the difference between
this.

> 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.harter@itt.com >
> >

Ralf


--
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/

  reply	other threads:[~2001-09-06  2:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-05 23:36 Fritz, Wolfgang
2001-09-06  2:25 ` Ralf Habacker [this message]
2001-09-06  3:58   ` Nick Drage
2001-09-06  5:46 ` Wayne Willcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000701c136b1$45efcfa0$651c440a@BRAMSCHE' \
    --to=ralf.habacker@freenet.de \
    --cc=cygwin@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).