perl + 忽略 perl 中的“/”字符

perl + 忽略 perl 中的“/”字符

我想用 America/Jamaica 替换字符串 America/Adak:

       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

查看珍珠岩请参阅手册页。

相关内容