public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE:  "if" "then" "elif" "fi" "done"
@ 2001-09-05 23:36 Fritz, Wolfgang
  2001-09-06  2:25 ` AW: " Ralf Habacker
  2001-09-06  5:46 ` Wayne Willcox
  0 siblings, 2 replies; 6+ messages in thread
From: Fritz, Wolfgang @ 2001-09-05 23:36 UTC (permalink / raw)
  To: cygwin

> -----Original Message-----
> From: Harter, Pete [ mailto:Pete.Harter@itt.com ]
> Sent: Thursday, September 06, 2001 8:02 AM
> To: 'cygwin@cygwin.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.harter@itt.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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* AW: "if" "then" "elif" "fi" "done"
  2001-09-05 23:36 "if" "then" "elif" "fi" "done" Fritz, Wolfgang
@ 2001-09-06  2:25 ` Ralf Habacker
  2001-09-06  3:58   ` Nick Drage
  2001-09-06  5:46 ` Wayne Willcox
  1 sibling, 1 reply; 6+ messages in thread
From: Ralf Habacker @ 2001-09-06  2:25 UTC (permalink / raw)
  To: Cygwin

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "if" "then" "elif" "fi" "done"
  2001-09-06  2:25 ` AW: " Ralf Habacker
@ 2001-09-06  3:58   ` Nick Drage
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Drage @ 2001-09-06  3:58 UTC (permalink / raw)
  To: cygwin

On Thu, Sep 06, 2001 at 10:52:35AM +0200, Ralf Habacker wrote:
<snip LOADS of quoted text >

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

The Advanced Bash Scripting HOWTO is an excellent document for getting to
grips with that kind of issue:

http://www.linuxdoc.org/LDP/abs/html/

<snip another HUGE amount of quoted text>

*sheesh*, find the delete key :)

-- 
isomorphisms accompanist so 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "if" "then" "elif" "fi" "done"
  2001-09-05 23:36 "if" "then" "elif" "fi" "done" Fritz, Wolfgang
  2001-09-06  2:25 ` AW: " Ralf Habacker
@ 2001-09-06  5:46 ` Wayne Willcox
  1 sibling, 0 replies; 6+ messages in thread
From: Wayne Willcox @ 2001-09-06  5:46 UTC (permalink / raw)
  To: Fritz, Wolfgang; +Cc: cygwin

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.Harter@itt.com ]
> > Sent: Thursday, September 06, 2001 8:02 AM
> > To: 'cygwin@cygwin.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.harter@itt.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@reliant.immure.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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: "if" "then" "elif" "fi" "done"
@ 2001-09-06 10:55 Heribert Dahms
  0 siblings, 0 replies; 6+ messages in thread
From: Heribert Dahms @ 2001-09-06 10:55 UTC (permalink / raw)
  To: 'Harter, Pete', 'cygwin@cygwin.com'

Hi Pete,

I'd use something like (untested):

	cat $pdt/$pcase/$pcase`print %03d $pi`.bdf >> $pdt/$pcase.temp


Bye, Heribert (heribert_dahms@icon-gmbh.de)

> -----Original Message-----
> From:	Harter, Pete [SMTP:Pete.Harter@itt.com]
> Sent:	Thursday, September 06, 2001 08:02
> To:	'cygwin@cygwin.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.
> 
> 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 >
> 
> 
> --
> 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* "if" "then" "elif" "fi" "done"
@ 2001-09-05 23:01 Harter, Pete
  0 siblings, 0 replies; 6+ messages in thread
From: Harter, Pete @ 2001-09-05 23:01 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

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.

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 >


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-09-06 10:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-05 23:36 "if" "then" "elif" "fi" "done" Fritz, Wolfgang
2001-09-06  2:25 ` AW: " Ralf Habacker
2001-09-06  3:58   ` Nick Drage
2001-09-06  5:46 ` Wayne Willcox
  -- strict thread matches above, loose matches on Subject: below --
2001-09-06 10:55 Heribert Dahms
2001-09-05 23:01 Harter, Pete

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).