“缺少操作员”使用“set /a”时出现错误消息命令
好吧,我已经完成了名为“stringparsing.bat”的批处理程序,当我使用以下代码片段时,我遇到的最后一个错误是“缺少运算符”:
set /p linecount=
cls
set foo=0
set linenumber=0
:lineset
set /a linenumber=%linenumber% +1
set /p line1= %linenumber%
echo %line1% >> %name%.txt
set /a foo=%foo%+1
set /a line number=%linenumber%+1
IF %foo%==%linecount% goto MAIN123
goto lineset
更具体地说,我将其范围缩小到:
set /a linenumber=%linenumber% +1
set /p line1= %linenumber%
我很确定我错误地使用了 set /p 命令...我想做的是发出一个提示,要求用户输入要插入文本中的文本行数文件。然后创建一个循环,要求用户输入一些文本,然后将其发送到文本文件。但我想将行号放在提示之前,以便它看起来像这样:
所以当批处理file 要求第一行时,它会显示 1: ,当它要求第二行时,它会显示 2: ,依此类推。每行提示后,我都会收到“缺少运算符”错误消息...顺便说一句,我需要使用此脚本才能使其正常工作:
set /p line1= %linenumber%+1
但为了将此命令与 < strong>+1 最后,我是否必须添加 /a 参数以及 /p 参数?
有什么想法吗?
Ok so ive been finishing off my batch program called "stringparsing.bat" and the last error im having trouble with is one that says "missing operator" when i use the following snippet:
set /p linecount=
cls
set foo=0
set linenumber=0
:lineset
set /a linenumber=%linenumber% +1
set /p line1= %linenumber%
echo %line1% >> %name%.txt
set /a foo=%foo%+1
set /a line number=%linenumber%+1
IF %foo%==%linecount% goto MAIN123
goto lineset
More specificly, ive narrowed it down to :
set /a linenumber=%linenumber% +1
set /p line1= %linenumber%
Im pretty sure im mis-using the set /p command... what i am trying to do, is make a prompt that asks the user to input how many lines of text that they are going to insert into a text file. Then make a loop that asks the user to type some text which is then sent to the text file. But i wanted to to put the line number before the prompt so that it would look like this:
So when the batch file asks for the first line, it says 1: , and when it asks for the second line, its says 2: , and so on. after each line prompt, i get the "missing operator" error message... Btw i need to use this scirpt to get it to work:
set /p line1= %linenumber%+1
But in order to use this command with the +1 at the end, do i have to add the /a parameter as well as the /p parameter?
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个简单的 echo on 在这里可以有所帮助:-)
在你的行中 set /a line number=%linenumber%+1 是一个空格行号,这是一个问题。
还有一点,不是一定要用,
还是用比较好
A simple echo on could help here :-)
In your line set /a line number=%linenumber%+1 is a space linenumber, that is a problem.
Another thing, it is not neccessary to use
It is better to use
Set /A 无法处理分数,即带小数点的数字。放 /?说:
Set /A cannot handle fractions aka numbers with decimal points. Set /? says: