批处理文件IF语句失败,"在这个时候&QUOT意外; [英] Batch file IF statement fails with "was unexpected at this time"
问题描述
我有一个批处理文件,执行以下操作:
I have a batch file that does the following:
@IF EXIST "C:\Program Files\MyAppFolder" (
icacls "C:\Program Files\MyAppFolder" /inheritance:r
icacls "C:\Program Files\MyAppFolder" /GRANT SYSTEM:(CI)(OI)(F)
icacls "C:\Program Files\MyAppFolder" /GRANT Administrators:(CI)(OI)(F)
)
单独的命令的工作不错,但放在一起这样在如果
语句我得到这个错误和脚本在其轨道站:
Individually the commands work fine but put together like this in an IF
statement I get this error and the script stops in its tracks:
(OI)(F) was unexpected at this time.
如果我只是在如果
语句一条命令然后正常工作。
If I just have a single command in the IF
statement then it works fine.
我猜你只允许如果
括号之间的一个声明?
I'm guessing that you're only permitted one statement between the IF
parenthesis?
这发生在Windows 2008和Windows 2003(与ICACLS修补程序)。
This happens on Windows 2008 and Windows 2003 (with the ICACLS hotfix).
推荐答案
外壳似乎认为)
在你的第二个命令行是一个右括号在第一线开通。你需要使用引号包含括号中的参数:
The shell seems to think that the )
in your second command line is the closing parenthesis for the one opened in the first line. You need to quote the arguments containing parenthesis:
@IF EXIST "C:\Program Files\MyAppFolder" (
icacls "C:\Program Files\MyAppFolder" /inheritance:r
icacls "C:\Program Files\MyAppFolder" /GRANT "SYSTEM:(CI)(OI)(F)"
icacls "C:\Program Files\MyAppFolder" /GRANT "Administrators:(CI)(OI)(F)"
)
这篇关于批处理文件IF语句失败,"在这个时候&QUOT意外;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!