Windows批处理脚本中的sed命令
问题描述:
我需要获取现有目录的绝对路径并更改其中一个属性。 我为这个任务编写了简单的脚本,并且在我的linux机器上一切都很好。Windows批处理脚本中的sed命令
SET "IGNITE_PATH=%cd%\standalone\configuration\ignite.xml"
sed -i -r "s#([email protected]\/scripts-dir-path=).*#\1%SCRIPTS_PATH%#g" .\standalone\configuration\platform-config.properties
这个脚本的Resul的样子:
[email protected]/ignite-config-path=/c/../standalone/configuration/ignite.xml
然后,我适应了这个脚本为Windows用户。
SET "IGNITE_PATH=%cd%\standalone\configuration\ignite.xml"
sed -i -r "s#([email protected]\/ignite-config-path=).*#\1%IGNITE_PATH%#g" .\standalone\configuration\platform-config.properties
但面临问题。蝙蝠的Windows脚本的结果如下:
[email protected]/ignite-config-path=C:DESKTOP...STANDALONENFIGURATIONIGNITE.XML
所有路径呈现大写锁定为一个字和一些字的模样stucked在一起。
这是因为unix和Windows上的不同分隔符的行为吗?在这种情况下什么是解决方案?
答
我不知道该工具sed
但我相信它预计正斜杠/
是路径分隔符,因为它来自于Unix系统。
但是,Windows命令解释器(cmd
)使用反斜杠\
作为路径分隔符。
因此,我建议你SET
命令行后立即插入下面一行:
SET "IGNITE_PATH=%IGNITE_PATH:\=/%"
它使用sub-string replacement syntax由/
更换每\
。
尝试转义SET中的反斜杠“IGNORE_PATH ... – drewster
我不知道'sed'实际上期望的是什么,但也许它需要正斜杠'/'作为路径分隔符;如果是,请执行'SET' IGNITE_PATH =%IGNITE_PATH:\ = /%“'在你的'SET'命令行之后... – aschipfl
@aschipfl谢谢你!很好。 – rnknown