`
sunxboy
  • 浏览: 2832182 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

如何处理 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//\//\\/}"

 

可解决问题。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics