bash-2.x

Lassi A. Tuura lat@iki.fi
Fri Jul 24 11:17:00 GMT 1998


|>        for name [ in word; ] do list ; done
|>               The list of words following in is expanded,  gener-
|>               ating a list of items.  The variable name is set to
|>               each element of this list in turn, and list is exe-
|>               cuted  each  time.   If the in word is omitted, the
|>               for command executes list once for each  positional
|>               parameter  that is set (see PARAMETERS below).  The
|>               return status is the exit status of the  last  com-
|>               mand  that executes.  If the expansion of the items
|>               following in results in an empty list, no  commands
|>               are executed, and the return status is 0.
|> 
|> Which means that empy word-list is valid, and shouldn't trigger
|> an error.
|>     10:55:25 mub ~/ftp/gnu/bash-2.02$ for i in ;do echo $i; done
|>     bash: syntax error near unexpected token `;d'

No, bash behaves as described.  Legal syntax is one of these: 
  for i in x1 x2; do echo $i; done
  for i do echo $i; done
  for i; do echo $i; done
  dummy=; for i in $dummy; do echo $i; done

It is not legal to say `for i in ; do'.  The list after `in' can be
empty only as a consequence of expansion (shell variable or file name),
not before the expansion; reread the documentation you quoted.  Hence,
if you omit the `word' list, you must omit `in' as well.

If you are using this inside makefiles where you don't know whether the
list is going to be empty or not, you can use something like this: 
  for i in $(list) ..; do		# $(list) may be empty, and is
    if [ x$$i =  x.. ]; then :; else	# expanded by make, not shell
      # commands
    fi
  done

Cheers,
//lat
--
With sufficient thrust, pigs fly just fine.  However, this is not
necessarily a good idea.  It is hard to be sure where they are going
to land, and it could be dangerous sitting under them as they fly
overhead.  --RFC1925, "The Twelve Networking Truths"

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list