gpt4 book ai didi

windows - =y此时出乎意料

转载 作者:可可西里 更新时间:2023-11-01 09:28:09 26 4
gpt4 key购买 nike

我正在尝试制作一个脚本来在 Windows 上自动安装软件包,但我不断收到

=y was unexpected at this time

这是怎么回事?

@echo off
echo Checking Internet...
Ping www.google.com -n 1 -w 1000
cls
if errorlevel 1 (set internet=n) else (set internet=y)
if %internet%=y goto start
if %internet%=n goto warn
:warn
echo Warning! You are not connected to the Internet.
echo Chocolatey will not install until you connect and
echo run this batchfile again.
echo Press any key to continue anyways.
pause >nul
:start
echo Copying...
echo [sudo.exe]
mkdir C:\pkg
copy sudo.exe C:\pkg
sudo xcopy C:\pkg\sudo.exe C:\Windows
echo [chocolatey.bat]
copy chocolatey.bat C:\pkg
echo [package.bat]
copy package.bat C:\pkg
echo Installing Choco...
if %internet%=y sudo C:\pkg\chocolatey.bat
if %internet%=n echo Cancelled: No internet.
echo Press any key when complete.
pause >nul
echo Installing Packages...
if %internet%=y sudo C:\pkg\package.bat
if %internet%=n echo Cancelled: No internet.
echo Press any key when complete

注意:我使用“sudo.exe”来提升权限。我不打算在 Windows 中使用 bash。

最佳答案

我一直收到“=y was unexpected at this time”这是怎么回事?

if %internet%=y goto start

= 不是有效的比较运算符,您应该使用 ==:

if %internet%==y goto start

这适用于您所有的 if %internet% 命令。


语法

F:\test>if /?
Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

NOT Specifies that Windows should carry out
the command only if the condition is false.

ERRORLEVEL number Specifies a true condition if the last program run
returned an exit code equal to or greater than the number
specified.

string1==string2 Specifies a true condition if the specified text strings
match.

进一步阅读

关于windows - =y此时出乎意料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38317547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com