批量保存不正确 [英] Batch not saving properly

查看:79
本文介绍了批量保存不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@echo off 
title IPBlocker
:MAIN 
color A 
echo ====================================
echo Hello, his tool will help to block an IP from accessing you. 
set /p localip= What's your local IP [Default: 192.168.1.1]:
set /p user= Enter your router's username [root by default]:
set /p password= Enter your router's password:
set /p IP= Which IP do you want to block:
echo ==================================== 
echo printf \n%IP% >> /etc/config/blacklistips; /etc/init.d/firewall restart> blockedips.txt

echo The IP has been succesfully blocked and your router's firewall restarted.
pause

您好,所以我正在尝试创建此批处理,但是当我运行它时,我猜它可能在某个地方坏了.

Hello, so I'm trying to create this batch, but when I run it I guess it breaks somewhere.

应该在blockedips.txt中保存"printf \ n%IP%>>/etc/config/blacklistips;/etc/init.d/firewall restart",但保存"printf \ n;/etc/init .d/防火墙重新启动".因此,出于某种原因,该">>/etc/config/blacklistips"未包含在文件中.我的问题是为什么.

Is should save "printf \n%IP% >> /etc/config/blacklistips; /etc/init.d/firewall restart" in blockedips.txt, but instead it saves "printf \n ; /etc/init.d/firewall restart". So this ">> /etc/config/blacklistips" is not including in the file for some reason. And my question is why.

user,password和localip稍后在与Putty连接时会在其他位置使用(是否已完成脚本,仍然没有按原样保存).主要问题是它没有在文本文件中保存必要的信息.

user, password and localip are used elsewhere later on connect with Putty (complete script or not, still doesn't save as it should). The main problem is that it doesn't save the necessary info in the text file.

推荐答案

通过使用插入符号将它们转义,如下所示:

Escape them by using the caret symbol like this:

^>^>

原因是它是批处理中的特殊字符,因此必须转义.
现在,这些符号被视为文字字符.

Reason is that it is a special character in batch so it has to be escaped.
Now the symbols are treated as literal characters.

这篇关于批量保存不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆