Recently I found a part of code which confuses me:
typeset _Var=''
for _Var
do
... a command
done
can anyone explain how this loops through an empty list of values is working?
thanks a lot for any post.
The construct
for var
do
echo something
done
without the in keyword will default to the list of positional parameters, e.g., $1, $2, etc.
So your script will execute the loop body once for each separate argument on the command line.
The snippet above invoked as ksh testscript a b c will output:
something
something
something
typeset _Var=''is a red herring. The for keyword will provide _Var with other values, explicit with the in keyword, or implicit with out. See below.for x+ newline(!) +dois equivalent to POSIX shellfor x in "$@"; do. Note that you cannot usefor x; dobecause some shells misparse that. Source: GNU autoconf texinfo manual, section about portable shell.