shell 下图中的make文件中sed有什么用?[副本]

7kjnsjlb  于 2023-05-18  发布在  Shell
关注(0)|答案(1)|浏览(191)

此问题已在此处有答案

What does command sed -i "s/^ \+//g; s/ \+/\t/g" mean?(1个答案)
6天前关闭。
我正在跟随教程https://makefiletutorial.com/#pattern-rules
递归使用make
要递归地调用makefile,请使用特殊的$(MAKE)而不是make,因为它将为您传递make标志,而本身不会受到它们的影响。

new_contents = "hello:\n\ttouch inside_file"
all:
  mkdir -p subdir
  printf $(new_contents) | sed -e 's/^ //' > subdir/makefile
  cd subdir && $(MAKE)

clean:
  rm -rf subdir

我不明白这句台词

printf $(new_contents) | sed -e 's/^ //' > subdir/makefile

谁知道sed -e 's/^ //'在做什么?
我尝试编译并在子文件夹中生成make文件。

a5g8bdjr

a5g8bdjr1#

你的问题似乎有点不具体。你有什么不明白的?
在以下行中:

printf $(new_contents) | sed -e 's/^ //' > subdir/makefile
  • printf $(new_contents)将Make变量new_contents的内容写入stdout
  • sed -e 's/^ //'在内容中搜索以前导空格开头的任何行并删除此空格。s/^ //是正则表达式。顺便说一句,-e选项在这种情况下是不必要的,但它更明确。
  • > subdir/makefile将结果写入子目录 subdir 中名为 makefile 的文件

就是这样

相关问题