sed -i command for in-place editing to work with both GNU sed and BSD/OSX
问题 I've got a makefile (developed for gmake on Linux) that I'm attempting to port to MacOS, but it seems like sed doesn't want to cooperate. What I do is use GCC to autogenerate dependency files, and then tweak them a bit using sed . The relevant portion of the makefile : $(OBJ_DIR)/%.d: $(SRC_DIR)/%.cpp $(CPPC) -MM -MD $< -o $@ sed -i 's|\(.*\)\.o:|$(OBJ_DIR)/\1.o $(OBJ_DIR)/\1.d $(TEST_OBJ_DIR)/\1_utest.o:|' $@ While this runs with no trouble under GNU/Linux, I get errors like the following