看板 Perl 關於我們 聯絡資訊
想問一下如何在 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