awk - Makefile Awk 使用 $ 表示列出现语法错误,但在控制台上运行良好

标签 awk makefile syntax-error

我在控制台上使用下面的行非常好,但是当我在 makefile 中使用它时,我收到以下错误。过去一小时我尝试了不同的事情,但没有任何帮助。另外我必须在 makefile 中的命令之前使用“@”,这只是正常的。非常欢迎任何帮助。

控制台命令

cpio -itv < rootfs.cpio | awk '!/^d/{$8="";print}' | sort -k8 > rootfs.layout.trim

错误

awk: !/^d/{="";print}
awk:       ^ syntax error

在 makefile 中

log-rootfs:
# copy the layout dump with all the modification needed to sync with stb output
# get the file list from cpio file => remove the lines with directory name => sort the output and store the same in layout file
cpio -itv < $(ROOTFS_CPIO_FILE) | awk '!/^d/{$8="";print}' | sort -k8 > $(ROOTFS_LAYOUT)
@echo $(ROOTFS_LAYOUT) is created

最佳答案

make 正在寻找名为 $8 的变量/宏。一般来说,$需要在makefile中进行转义,如果你想将文字$传递给shell,你应该使用$$ 在 makefile 中。换句话说,尝试:

rule:
  ... awk '!/^d/{$$8="";print}' ...

关于awk - Makefile Awk 使用 $ 表示列出现语法错误,但在控制台上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18467100/

相关文章:

linux - 使用sed删除文件中的行

c - 使用 Makefile 进行简单编译?

c++ - undefined reference - 为什么链接时找不到头文件中的某些方法?

jquery - <div> onclick未被捕获的SyntaxError?

javascript - 为什么我收到错误 "button.addEventListener is not a function"

Linux:复制最近的目录(名称有空格)

linux - 计算文本文件中的一致性和相关性

oracle - 管道破裂迭代?

c - 为什么我的正则表达式在 Makefile 中中断?

javascript - 在 propTypes 中 react 错误