对于一组项目,我需要自动授予用户访问权限,并编写一个 *.bat
我会写类似这样的内容(但更复杂):
@echo off
CALL :grant "user1 user2" "read write delete"
CALL :grant "groupa groupb" "read"
ECHO All Done
GOTO :eof
:grant
ECHO %0 is called with arguments %1 and %2
for %%a in (%1) do (
for %%b in (%2) do (
echo grant %%a %%b
rem here come the actual commands
)
)
EXIT /B
并预期这样的输出
:grant is called with arguments user1 user2 and read write delete
grant user1 read
grant user1 write
grant user1 delete
grant user2 read
grant user2 write
grant user2 delete
:grant is called with arguments groupa groupb and read
grant groupa read
grant groupb read
All Done
但我得到的却是
:grant is called with arguments "user1 user2" and "read write delete"
grant "user1 user2" "read write delete"
:grant is called with arguments "groupa groupb" "read"
grant "groupa groupb" "read"
All Done
我该如何解决这个问题?
答案1
@echo off
CALL :grant "user1 user2" "read write delete"
echo _
CALL :grant "groupa groupb" "read"
ECHO All Done
GOTO :eof
:grant
ECHO %0 is called with arguments %1 %2
set identities=%1
set accessList=%2
for %%a in (%identities:"=%) do (
for %%b in (%accessList:"=%) do (
echo grant %%a %%b
)
)
EXIT /B