[問題] 在 shell/shell script 下做斜線取代
想問一下如何在 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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章