Home > Backend Development > Golang > Why Does My Makefile Command Fail When Using Shell Expressions?

Why Does My Makefile Command Fail When Using Shell Expressions?

Patricia Arquette
Release: 2024-12-26 01:46:09
Original
863 people have browsed it

Why Does My Makefile Command Fail When Using Shell Expressions?

Makefile Evaluation of Expressions

When working with Makefiles, it's essential to understand how expressions are interpolated into commands. A common pitfall arises when trying to incorporate shell expressions into Makefile commands.

One such case is when working with Go tests. To skip dependencies in a vendored Go project, one might use the following command from the command line:

$ go test $(go list ./... | grep -v /vendor/)
Copy after login

This command successfully filters out Vendored tests. However, when attempting to include the same command in a Makefile using the following:

test:
    go test $(go list ./... | grep -v /vendor/)

.PHONY: test
Copy after login

The expression will not be evaluated. Instead, the command will be treated literally, leading to an error.

To resolve this issue, double-escape the dollar sign ($), as shown below:

test:
    go test $$(go list ./... | grep -v /vendor/)

.PHONY: test
Copy after login

By double-escaping the dollar sign, the Makefile understands that the expression should be evaluated by a shell, enabling the successful interpolation and execution of the command.

The above is the detailed content of Why Does My Makefile Command Fail When Using Shell Expressions?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template