perl + perl의 "/" 문자 무시

perl + perl의 "/" 문자 무시

다음과 같이 America/Adak 문자열을 America/Jamaica로 바꾸고 싶습니다.

       perl -i -pe "s/$A/$B/"  /etc/sysconfig/clock 

Perl 구문에서 업데이트해야 할 사항에 대해 조언을 부탁드립니다. (문제는 "/"가 있으므로 이 고유 문자를 무시해야 한다는 것입니다. Perl 구문에 무엇을 추가해야 합니까?

 A="America/Adak"
 B="America/Jamaica"
 CLOCK=/etc/sysconfig/clock

 perl -i -pe "s/$A/$B/" $CLOCK

 Bareword found where operator expected at -e line 1, near "s/America/Adak/America"
 syntax error at -e line 1, near "s/America/Adak/America"
 Execution of -e aborted due to compilation errors.

 more $CLOCK
 # The ZONE parameter is only evaluated by system-config-date.
 # The timezone of the system is defined by the contents of /etc/localtime.
 ZONE="America/Adak"
 UTC=true
 ARC=false

답변1

다른 구분 기호를 사용하세요. 예를 들면 다음과 같습니다.

perl -i -pe "s|$A|$B|" $CLOCK

참조펄레맨 페이지.

관련 정보