[英]Issues replacing backslashes in paths
我正在嘗試替換 Windows 路徑中的反斜杠,以便我可以將路徑粘貼到 Filezilla 中以打開文件夾,而無需在目錄結構中進行瀏覽。 我使用以下命令:
echo '\path\to\the\05_directory' | sed -e 's/\\/\//g'
我的預期結果是
/path/to/the/05_directory
但我得到了
/path o he_directory
似乎\\t
和\\05
被解釋為文字字符串以外的東西。
為什么會發生這種情況? 我該如何解決這個問題?
您可以使用printf "%q"
打印文字\\
vs 將它們解釋為制表符:
printf "%q" '\path\to\the\05_directory'
\\path\\to\\the\\05_directory
然后你可以使用sed
來獲取你的輸出:
printf "%q" '\path\to\the\05_directory' | sed -e 's|\\\\|/|g'
/path/to/the/05_directory
"%q"
字段准備在 shell 中使用的字符串。 這當然意味着' '
將被轉義:
printf "%q" '\path\to\the\05 directory'
\\path\\to\\the\\05\ directory
您可以單獨清理:
printf "%q" '\path\to\the\05 directory' | sed -e 's|\\\\|/|g; s|\\||g'
/path/to/the/05 directory
我試圖替換Windows路徑中的反斜杠,以便可以將路徑粘貼到Filezilla中以打開文件夾,而不必在目錄結構中瀏覽器。 我使用以下命令:
echo '\path\to\the\05_directory' | sed -e 's/\\/\//g'
我的預期結果是
/path/to/the/05_directory
但是我得到了
/path o he_directory
看來\\t
和\\05
被解釋為非文字字符串。
為什么會這樣? 我該如何解決?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.