如何处理 bash shell 变量中的斜杠(/)?

 
#!/bin/bash
## Our path
_r1="/nfs/apache/logs/rawlogs/access.log"
 
## Escape path for sed using bash find and replace 
_r1="${_r1//\//\\/}"
 
# replace __DOMAIN_LOG_FILE__ in our sample.awstats.conf
sed -e "s/__DOMAIN_LOG_FILE__/${_r1}/" /nfs/conf/awstats/sample.awstats.conf  > /nfs/apache/logs/awstats/awstats.conf

如上,代码变量_r1值中有“\”,但是在sed命令中这个值是需要处理一下的。

_r1="${_r1//\//\\/}"

可解决问题。

猜你喜欢

转载自sunxboy.iteye.com/blog/2184824