我正在尝试使用 Windows 内置 shell 脚本来加载此文件:
hostname1,host_specific_file1
hostname2,host_specific_file2
hostname3,host_specific_file3
.
.
.
像这样:
for /f "tokens=1,2* delims=," %%i in (host-info.txt) do set clientName=%%i; set fileLoc=%%j
这不起作用,但我希望它像这样:
:loop
For each line, Set the current_hostname=hostnamex and Set the current_file=host_specific_filex
And THEN
DO STUFF
Goto next line, Goto loop
有没有办法做到这一点?我无法让我的脚本围绕“转到下一行”或“一次处理一行”概念。
谢谢, 克里斯
最佳答案
你可以;
echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2* delims=," %%i in (host-info.txt) do (
set clientName=%%i
set fileLoc=%%j
call:handler
)
goto:eof
:handler
echo client name is !clientName! location is !fileLoc!
goto:eof
或者使用 %n 表示法;
echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2* delims=," %%i in (host-info.txt) do call:handler %%i %%j
goto:eof
:handler
echo client name is %1 location is %2 ...
关于将 csv 加载到变量中的 Windows Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7256984/