Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Short loops?



"Bart Schaefer" wrote:
> Peter, how about adding something about this to the FAQ as well?

It looks like I should be adding two things to the FAQ.  This is the
deyodled text.


3.6: Why does zsh not work in an Emacs shell mode any more?

  (The following is from Bart Schaefer again):

  Emacs 19.29 or thereabouts stopped using a terminal type of "emacs"
  in shell buffers, and instead sets it to "dumb".  Zsh only kicks in
  its special I'm-inside-emacs initialization when the terminal type
  is "emacs".

  Placing a

    (setenv "TERM" "emacs")

  in your ~/.emacs file seems to fix this.  If that confuses other programs
  that are run from within emacs, you can instead use

    (setenv "ESHELL" "~/bin/eshell")

  and then put `TERM=emacs exec zsh' in the file ~/bin/eshell.


3.16: How does the alternative loop syntax, e.g. `while {...} {...}' work?

  Zsh provides an alternative to the traditional sh-like forms with `do',

    while TEST; do COMMANDS; done

  allowing you to have the COMMANDS delimited with some other command
  structure, often `{...}'.  However, to make this work you must make
  sure the TEST itself is clearly delimited.  For example, this works:

    while (( i++ < 10 )) { echo i is $i; }

  but this does _not_:

    while let "i++ < 10"; { echo i is $i; }   # Wrong!

  The reason is that after `while', any sort of command list is valid.
  This includes the whole list `let "i++ < 10"; { echo i $i; }';
  the parser simply doesn't know when to stop.  Furthermore, it is
  wrong to miss out the semicolon, as this makes the `{...}' part
  of the argument to `let'.

  So when using this syntax, the test following the `while' must
  be wrapped up:  any of `((...))', `[[...]]', `{...}' or
  `(...)' will have this effect.  (They have their usual syntactic
  meanings too, of course; they are not interchangeable.)  Note that
  here too it is wrong to put in the semicolon, as then the case
  becomes identical to the preceding one:

    while (( i++ < 10 )); { echo i is $i; }   # Wrong!

  The same is true of the `if' and `until' constructs:

    if { true } { echo yes } else { echo no }

  but with `for', which only needs a list of words, you can get
  away with it:

    for foo in a b; { echo foo is $a; bar=$foo; }

  since the parser knows it only needs everything up to the first
  semicolon. For the same reason, there is no problem with the `repeat',
  `case' or `select' constructs; in fact, `repeat' doesn't even
  need the semicolon since it knows the repeat count is just one word.

  This is independent of the behaviour of the SHORTLOOPS option (see
  manual), which you are in any case encouraged not to use in programs
  as it can be very confusing.

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



Messages sorted by: Reverse Date, Date, Thread, Author