“缺少操作员”使用“set /a”时出现错误消息命令

发布于 2024-10-06 20:00:53 字数 933 浏览 0 评论 0原文

好吧,我已经完成了名为“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 命令...我想做的是发出一个提示,要求用户输入要插入文本中的文本行数文件。然后创建一个循环,要求用户输入一些文本,然后将其发送到文本文件。但我想将行号放在提示之前,以便它看起来像这样:

alt text

所以当批处理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:

alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白昼 2024-10-13 20:00:53

一个简单的 echo on 在这里可以有所帮助:-)

在你的行中 set /a line number=%linenumber%+1 是一个空格行号,这是一个问题。

还有一点,不是一定要用,

set /a linenumber=%linenumber% +1

还是用比较好

set /a linenumber=linenumber+1
or
set /a 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

set /a linenumber=%linenumber% +1

It is better to use

set /a linenumber=linenumber+1
or
set /a linenumber+=1
酸甜透明夹心 2024-10-13 20:00:53

Set /A 无法处理分数,即带小数点的数字。放 /?说:

数值均为十进制数,除非前缀为 0x
十六进制数,八进制数为 0。

Set /A cannot handle fractions aka numbers with decimal points. Set /? says:

Numeric values are decimal numbers, unless prefixed by 0x for
hexadecimal numbers, and 0 for octal numbers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文