Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

macos - sed throws 'bad flag in substitute command'

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

It throws this

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

What can be wrong in this simple script?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 '' ...

In your example:

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...