The [!]/?[/!] option of most shell commands will give you a wealth of information. For example,
for /? at a command prompt will explain the
for loop command in much more depth than I have given.
As for a complete example, there are plenty
already in existence and there are a few ways to do it depending on what you ultimately need.
I arbitrarilly picked 6 tokens so that you could see the last one(s) will have no value [depending on date format]. If you split the
date output into smaller parts using the
delims mentioned, you will find that there are fewer than 6. And you've missed 2 delimiters that I wrote. There are 3 total in my code above: the hyphen charater (
-), the space character ( ), and the forward slash character (
/).
In general, from within the command shell
%XXXXX% is how you'd call or use the variable
XXXXX. This variable could be something previously set (see
set /?), or it could be a system variable like
date. One exception to this variable notation is within a
for loop in a batch file -
%%XXXXX notation is used. So, in this case,
%%i is simply the variable
i.
in ('echo %DATE%') defines what the for loop is processing.
echo %DATE% is the
command that generates some output to be evaluated. You can tell this is a command (as opposed to a string or file set) because of the single quote marks surrounding it (see
for /?). The portion in the
for loop is in no way related to the second line of the batch file.
echo %DATE% stands alone as a command all by itself. The second line is only there for you (the human) to see the output of the variable %date% that gets evaluated inside the
for loop; it is not required for processing. You can remove the second line of the batch file and you simply won't see the current date echo'd (see
echo /?).
Yes,
do is the processing that is to be done based on the results of the
for loop. If it were only 1 command, it could be on the same line. Because this
does several commands, I have put each command on a seperate line & enclosed them all in parenthesese.