sed 在替代命令中抛出“坏标志" [英] sed throws 'bad flag in substitute command'

查看:22
本文介绍了sed 在替代命令中抛出“坏标志"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个简单的命令来替换 CSS 文件中相对路径的绝对路径,如下所示:

I want to run a simple command of replacing absolute paths to relative ones inside a CSS file like this:

sed -i 's//fonts/../fonts/' /Users/sergeybasharov/WebstormProjects/snap/compiled/Content/stylesheets/style.css

它抛出这个

sed: 1: "/Users/sergeybasharov/W ...": bad flag in substitute command: 'b'

这个简单的脚本有什么问题?

What can be wrong in this simple script?

推荐答案

在你的命令中 s//fonts/../fonts/ 被作为参数到 -i 选项(用于备份文件的后缀),并且文件名参数被视为编辑命令.

In your command s//fonts/../fonts/ is being taken as the parameter to the -i option (the suffix to use for the backup file), and the filename argument is being treated as the editing commands.

您需要指定禁用备份文件创建:

You need to specify to disable the backup file creation:

sed -i '' ...

在你的例子中:

sed -i '' 's//fonts/../fonts/' /Users/sergeybasharov/WebstormProjects/snap/compiled/Content/stylesheets/style.css

计算机是愚蠢的,它们不会根据上下文来解决问题,因此它们无法判断以 s/ 开头的内容显然是一个编辑命令,而不是一个后缀.

Computers are dumb, they don't figure things out by context, so they can't tell that something beginning with s/ is obviously an editing command, not a suffix.

这篇关于sed 在替代命令中抛出“坏标志"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆