sed為特殊字元加上跳脫字元問題 - Linux
By Emma
at 2022-03-08T11:50
at 2022-03-08T11:50
Table of Contents
情境:
將文字檔裡的wireless ssid取出並sed到另外一個文字檔。
問題:
遇上包含/的ssid,sed指令會出事。
stackoverflow找到的解法:
放變數的時候用 ${ssid//\//\\/}在/前面加上escape。
問題1:
match pattern是 /\/,看不懂第一個/的用途,實驗過用\/
當pattern輸出結果也是一樣,這是為什麼呢?
實驗方式
ssid="TEST/SSID"
echo ${ssid//\//\\/}
echo ${ssid/\//\\/}
輸出都是TEST\/SSID
問題2:
取代的字串是\\/,就我的認知應該兩個都要加escape所以應該是\\\/
實驗結果也是兩個輸出都一樣,why???
echo ${ssid//\//\\/}
echo ${ssid//\//\\\/}
--
將文字檔裡的wireless ssid取出並sed到另外一個文字檔。
問題:
遇上包含/的ssid,sed指令會出事。
stackoverflow找到的解法:
放變數的時候用 ${ssid//\//\\/}在/前面加上escape。
問題1:
match pattern是 /\/,看不懂第一個/的用途,實驗過用\/
當pattern輸出結果也是一樣,這是為什麼呢?
實驗方式
ssid="TEST/SSID"
echo ${ssid//\//\\/}
echo ${ssid/\//\\/}
輸出都是TEST\/SSID
問題2:
取代的字串是\\/,就我的認知應該兩個都要加escape所以應該是\\\/
實驗結果也是兩個輸出都一樣,why???
echo ${ssid//\//\\/}
echo ${ssid//\//\\\/}
--
Tags:
Linux
All Comments
By Cara
at 2022-03-09T23:01
at 2022-03-09T23:01
By Hedy
at 2022-03-11T10:11
at 2022-03-11T10:11
By Lily
at 2022-03-12T21:22
at 2022-03-12T21:22
By Ina
at 2022-03-14T08:33
at 2022-03-14T08:33
By Caroline
at 2022-03-15T19:43
at 2022-03-15T19:43
By Lily
at 2022-03-17T06:54
at 2022-03-17T06:54
By Sarah
at 2022-03-18T18:04
at 2022-03-18T18:04
By Lucy
at 2022-03-20T05:15
at 2022-03-20T05:15
By Kama
at 2022-03-21T16:25
at 2022-03-21T16:25
Related Posts
在NIS伺服器中修改密碼
By Caroline
at 2022-02-26T23:22
at 2022-02-26T23:22
Linux下解決鍵盤F1~F12失效的問題
By Mason
at 2022-02-26T23:09
at 2022-02-26T23:09
安裝時出現aclocal-1.15 missing
By Joe
at 2022-02-19T14:42
at 2022-02-19T14:42
power lose 對檔案系統傷害最低的手段
By Ina
at 2022-02-18T17:16
at 2022-02-18T17:16
如何遠端控制另一台電腦
By Oliver
at 2022-02-17T11:45
at 2022-02-17T11:45