What is wrong with this for loop in my script?
up vote
0
down vote
favorite
K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%
This doesn't work. Why?
K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.
K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>
windows-10 batch
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%
This doesn't work. Why?
K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.
K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>
windows-10 batch
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
To replace your space , simply use string substitutionEcho %date: =_%
– LotPings
yesterday
This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday
As I wrote in my first comment, double the percent signs of the for meta variables%%Iand%%JSee ss64.com/nt/for.html
– LotPings
yesterday
runfor /?and read it's output
– phuclv
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%
This doesn't work. Why?
K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.
K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>
windows-10 batch
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%
This doesn't work. Why?
K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.
K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>
windows-10 batch
windows-10 batch
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 18 hours ago
JakeGould
30.5k1093134
30.5k1093134
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
Francky Leyn
223
223
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
To replace your space , simply use string substitutionEcho %date: =_%
– LotPings
yesterday
This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday
As I wrote in my first comment, double the percent signs of the for meta variables%%Iand%%JSee ss64.com/nt/for.html
– LotPings
yesterday
runfor /?and read it's output
– phuclv
yesterday
add a comment |
1
To replace your space , simply use string substitutionEcho %date: =_%
– LotPings
yesterday
This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday
As I wrote in my first comment, double the percent signs of the for meta variables%%Iand%%JSee ss64.com/nt/for.html
– LotPings
yesterday
runfor /?and read it's output
– phuclv
yesterday
1
1
To replace your space , simply use string substitution
Echo %date: =_%– LotPings
yesterday
To replace your space , simply use string substitution
Echo %date: =_%– LotPings
yesterday
This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday
This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday
As I wrote in my first comment, double the percent signs of the for meta variables
%%I and %%J See ss64.com/nt/for.html– LotPings
yesterday
As I wrote in my first comment, double the percent signs of the for meta variables
%%I and %%J See ss64.com/nt/for.html– LotPings
yesterday
run
for /? and read it's output– phuclv
yesterday
run
for /? and read it's output– phuclv
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J
The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday
This is not additional information to be added to the question; this is the answer (albeit woefully terse).
– Scott
yesterday
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday
1
@JakeGould: The problem was that the OP was using%Iand%Jin a BAT file. The answer (shown above) is to use%%Iand%%Jinstead of%Iand%J. (I did say that it was woefully terse.)
– Scott
21 hours ago
1
@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J
The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday
This is not additional information to be added to the question; this is the answer (albeit woefully terse).
– Scott
yesterday
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday
1
@JakeGould: The problem was that the OP was using%Iand%Jin a BAT file. The answer (shown above) is to use%%Iand%%Jinstead of%Iand%J. (I did say that it was woefully terse.)
– Scott
21 hours ago
1
@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago
|
show 2 more comments
up vote
0
down vote
FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J
The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday
This is not additional information to be added to the question; this is the answer (albeit woefully terse).
– Scott
yesterday
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday
1
@JakeGould: The problem was that the OP was using%Iand%Jin a BAT file. The answer (shown above) is to use%%Iand%%Jinstead of%Iand%J. (I did say that it was woefully terse.)
– Scott
21 hours ago
1
@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago
|
show 2 more comments
up vote
0
down vote
up vote
0
down vote
FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J
The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J
The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 18 hours ago
JakeGould
30.5k1093134
30.5k1093134
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered yesterday
Francky Leyn
223
223
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday
This is not additional information to be added to the question; this is the answer (albeit woefully terse).
– Scott
yesterday
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday
1
@JakeGould: The problem was that the OP was using%Iand%Jin a BAT file. The answer (shown above) is to use%%Iand%%Jinstead of%Iand%J. (I did say that it was woefully terse.)
– Scott
21 hours ago
1
@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago
|
show 2 more comments
If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday
This is not additional information to be added to the question; this is the answer (albeit woefully terse).
– Scott
yesterday
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday
1
@JakeGould: The problem was that the OP was using%Iand%Jin a BAT file. The answer (shown above) is to use%%Iand%%Jinstead of%Iand%J. (I did say that it was woefully terse.)
– Scott
21 hours ago
1
@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago
If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday
If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday
This is not additional information to be added to the question; this is the answer (albeit woefully terse).
– Scott
yesterday
This is not additional information to be added to the question; this is the answer (albeit woefully terse).
– Scott
yesterday
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday
1
1
@JakeGould: The problem was that the OP was using
%I and %J in a BAT file. The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)– Scott
21 hours ago
@JakeGould: The problem was that the OP was using
%I and %J in a BAT file. The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)– Scott
21 hours ago
1
1
@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago
@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago
|
show 2 more comments
Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.
Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.
Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.
Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376063%2fwhat-is-wrong-with-this-for-loop-in-my-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
To replace your space , simply use string substitution
Echo %date: =_%– LotPings
yesterday
This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday
As I wrote in my first comment, double the percent signs of the for meta variables
%%Iand%%JSee ss64.com/nt/for.html– LotPings
yesterday
run
for /?and read it's output– phuclv
yesterday