Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is this a bug or a feature?
It seems to happen for unquoted alphanumerics.

Running GNU bash, version 4.1.5

for alpha01234; do echo $((++i)); done


share|improve this question
up vote 14 down vote accepted

That is a feature of the for compound command, as described by help for:

for: for NAME [in WORDS ... ] ; do COMMANDS; done

Execute commands for each member in a list.

The for loop executes a sequence of commands for each member in a list of items. If in WORDS ...; is not present, then in "$@" is assumed. For each element in WORDS, NAME is set to that element, and the COMMANDS are executed.

So the code you quoted is probably executed in a script which was called with 4 parameters.

share|improve this answer
Thanks... The thing that threw me completely was that it happened at the command line.. I actually didn't try it in a script.. I must have used set a b c d at some time recently. I often use set that way in a script for testing.. After restarting the terminal, it has stopped... (makes sense now).. – Peter.O Nov 24 '11 at 16:56

for x; do … is a shortcut for for x in "$@"; do …: it iterates over the positional parameters. If it loops four times, it means you have four positional parameters ($1 through $4).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.