Reputation: 1861
Inside Makefile I have like this:
release:
version=$$(poetry version | cut -f2 -d " ")
echo "release $$version"
If I run,the statements from my terminal they run without any problem.
> version=$(poetry version | cut -f2 -d " ")
> echo "release $version"
release 0.0.2
But if I run,
> make release
version=$(poetry version | cut -f2 -d " ")
echo release $version
release
You see in the output, beside release
the version no. is not shown.
Upvotes: 2
Views: 1110
Reputation: 781004
Each command in a makefile recipe is executed in its own shell process. So the variable assignment takes place on one shell process, which then exits and its variables are discarded. The echo
command executes in a new process that doesn't have that variable.
You need to escape the newline and use a ;
command delimiter to run the commands in the same process.
release:
version=$$(poetry version | cut -f2 -d " "); \
echo "release $$version"
Upvotes: 5