You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
set /a c[0]=1set /a c[1]=2set"c[2]=str"set /a c[3]=1set /a c[4]=0
Command:
Note
Supports control characters except double quotes: for /F ... in ("...with control characters except a double quote character...") do ...%%i or for /F "usebackq ..." ... in ('"...with control characters except a double quote character..."') do ...%%~i
Supports an empty value: for /F "usebackq ..." ... in ('""') do ... %%~i
Supports print of ' character as is: for /F "usebackq ..." ... in ('"...'....'..."') do ... %%~i
<nul closes the stdin handle to quit the set /P command immediately after a line print without the trailing line return (instead of echo | set /P ... which creates a child cmd.exe process): <nul set /P =...
In case of enabled variable expansion by default the forwarding setlocal DISABLEDELAYEDEXPANSION and trailing endlocal prevents lines from the early delayed expansion in both for F statement and in %%~i expression: setlocal DISABLEDELAYEDEXPANSION & (for /F "usebackq ..." ... in ('"...!...!..."') do ...%%~i) & endlocal, when setlocal DISABLEDELAYEDEXPANSION & for /F "usebackq ..." ... in ('"...!...!..."') do endlocal & ...%%~i prevents only in for /F statement
Double quotes in set "...=%%~i" expression does ignore trailing white space character(s) after the second double quote and so can be chained by the & operator
A closed parentheses in echo.%%~i) avoids print of a trailing white space character(s) after the closed parentheses
Caution
All values in for /F statement must be already without a double quote in between of '" and "': for /F "usebackq ..." ... in ('"...with control characters except a double quote character..."') do ...%%~i
Expression:
Command:
Note
for /F ... in ("...with control characters except a double quote character...") do ...%%iorfor /F "usebackq ..." ... in ('"...with control characters except a double quote character..."') do ...%%~ifor /F "usebackq ..." ... in ('""') do ... %%~i'character as is:for /F "usebackq ..." ... in ('"...'....'..."') do ... %%~ieol^=for the empty EOL (Empty EOL in `for /F` statement andry81/contools#5)<nulcloses the stdin handle to quit theset /Pcommand immediately after a line print without the trailing line return (instead ofecho | set /P ...which creates a childcmd.exeprocess):<nul set /P =...setlocal DISABLEDELAYEDEXPANSIONand trailingendlocalprevents lines from the early delayed expansion in bothfor Fstatement and in%%~iexpression:setlocal DISABLEDELAYEDEXPANSION & (for /F "usebackq ..." ... in ('"...!...!..."') do ...%%~i) & endlocal, whensetlocal DISABLEDELAYEDEXPANSION & for /F "usebackq ..." ... in ('"...!...!..."') do endlocal & ...%%~iprevents only infor /Fstatement^!infor /Fstatement suppresses the delayed expansion in%%~iafter theendlocal(`!` character can be escaped while `ENABLEDELAYEDEXPANSION` is used andry81/contools#33):setlocal DISABLEDELAYEDEXPANSION & for /F "usebackq ..." ... in ('"...^!...^!..."') do endlocal & ...%%~iset "...=%%~i"expression does ignore trailing white space character(s) after the second double quote and so can be chained by the&operatorecho.%%~i)avoids print of a trailing white space character(s) after the closed parenthesesCaution
All values in
for /Fstatement must be already without a double quote in between of'"and"':for /F "usebackq ..." ... in ('"...with control characters except a double quote character..."') do ...%%~iCaution
A
setexpression can set or reset an error level:Note
To workaround double quotes in variables you can simple remove (or even replace) them:
Batsh code:
Windows Batch equivalent script:
Result: