pev*_*vik 3 bash posix for-loop sh bashism
Reading LTP shell code it uses strange for loop syntax:
for arg; do
TCID="${TCID}_$arg"
done
Run Code Online (Sandbox Code Playgroud)
$arg, separating with $IFS, but when trying $ arg="aa bb"; for arg; do echo $arg; done and it prints nothing.P.P*_*.P. 10
It's a special way of handling command-line options using for loop.
It's equivalent to:
for arg in "$@"; do
TCID="${TCID}_$arg"
done
Run Code Online (Sandbox Code Playgroud)
It's not specific to bash. It's defined in POSIX:
The for Loop
The for loop shall execute a sequence of commands for each member in a list of items. The
forloop requires that the reserved wordsdoanddonebe used to delimit the sequence of commands.The format for the for loop is as follows:
Run Code Online (Sandbox Code Playgroud)for name [ in [word ... ]] do compound-list doneFirst, the list of words following
inshall be expanded to generate a list of items. Then, the variable name shall be set to each item, in turn, and thecompound-listexecuted each time. If no items result from the expansion, thecompound-listshall not be executed. Omitting:Run Code Online (Sandbox Code Playgroud)in word ...shall be equivalent to:
Run Code Online (Sandbox Code Playgroud)in "$@"