douliangbian7323 2016-01-29 00:13
浏览 63

某些Sed替换不能用于Bash脚本

I have a script that does a fair bit of sed substitution and it all works baring this one line.

The odd thing is it works fine when I just run it normally on the terminal.

The code I want to substitute is part of this block:

location ~ \.php$ {
  try_files $uri =404;
  fastcgi_pass unix:/var/run/php-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

Particularly this line: fastcgi_pass unix:/var/run/php-fpm.sock; I want to change.

Here's the code I use to attempt to substitute it:

sed -i "s#fastcgi_pass unix:/var/run/php-fpm.sock;#fastcgi_pass unix:/var/run/php7.0-fpm.sock;#" /etc/nginx/sites-available/lemp-stack.app

For some reason it just doesn't substitute.

Does anybody have any ideas?

Thank you.

  • 写回答

1条回答 默认 最新

  • doulangpeng3933 2016-01-29 07:50
    关注

    There might be a tab instead of a space between pass and unix, if it is the case, this should work:

    sed "s#fastcgi_pass[ \t]unix:/var/run/php-fpm.sock;#fastcgi_pass unix:/var/run/php7.0-fpm.sock;#"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记