[問題] 在 shell/shell script 下做斜線取代

看板Perl作者 (C語言)時間14年前 (2011/06/20 13:11), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
想問一下如何在 shell/shell script 下使用反斜線取代? 試著處理反斜線的取代,但是失敗了 在 test.sh 中使用 perl: 1. 只取代一個英文 word -> ok #!/bin/bash string="pre-string\\middle\\post-string"; echo $string; string2=`echo $string | perl -pe s/middle/in_the_middle/;`; echo "string2 = $string2"; 輸出 pre-string\middle\post-string string2 = pre-string\in_the_middle\post-string 2. 試著取代反斜線 #!/bin/bash string="pre-string\\middle\\post-string"; echo $string; string2=`echo $string | perl -pe "s/\\middle\\/in_the_middle/;"`; echo "string2 = $string2"; 輸出: pre-string\middle\post-string Substitution replacement not terminated at -e line 1. string2 = 請問應該怎麼使用? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.57.131.154
文章代碼(AID): #1D_jPwwU (Perl)
文章代碼(AID): #1D_jPwwU (Perl)