簡體   English   中英

Windows批處理腳本中的sed命令

[英]Sed command in Windows batch script

我需要獲取現有目錄的絕對路徑並更改其屬性之一。 我為此任務編寫了簡單的腳本,並且一切都在我的linux機器上運行良好。

SET "IGNITE_PATH=%cd%\standalone\configuration\ignite.xml"
sed -i -r "s#(core@node\/scripts-dir-path=).*#\1%SCRIPTS_PATH%#g" .\standalone\configuration\platform-config.properties

該腳本的結果如下:

core@node/ignite-config-path=/c/../standalone/configuration/ignite.xml

然后,我為Windows用戶改編了該腳本。

SET "IGNITE_PATH=%cd%\standalone\configuration\ignite.xml"
sed -i -r "s#(core@node\/ignite-config-path=).*#\1%IGNITE_PATH%#g" .\standalone\configuration\platform-config.properties

但是面臨問題。 Windows bat腳本的結果如下:

core@node/ignite-config-path=C:DESKTOP...STANDALONENFIGURATIONIGNITE.XML

大寫鎖定中的所有路徑都作為單個單詞鎖定,並且某些單詞看起來像粘在一起。

這是由於Unix和Windows上的分隔符不同導致的嗎? 在這種情況下將有什么解決方案?

我不知道該工具是sed但我認為它期望正斜杠/是來自Unix系統的路徑分隔符。
Windows命令解釋器( cmd )使用反斜杠\\作為路徑分隔符。
因此,我建議在SET命令行后立即插入以下行:

SET "IGNITE_PATH=%IGNITE_PATH:\=/%"

這使用子字符串替換語法將每個\\替換為/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM