I want to create a temporary file and pipe some text into it using a makefile.
In bash, I can create a temp file and pipe text into it like so:
temp_file=$(mktemp)
echo "text goes into file" > ${temp_file}
cat ${temp_file}
rm ${temp_file}
Output when running it (as expected):
text goes into file
When using the same code in a makefile, I get the following output:
makefile:
test:
temp_file=$(mktemp)
echo "text goes into file" > ${temp_file}
cat ${temp_file}
rm ${temp_file}
$make test
echo "text goes into file" > /bin/sh: -c: line 1: syntax error near
unexpected token newline' /bin/sh: -c: line 1:
echo "text goes into
file" > ' make: *** [makefile:18: test] Error 2
Any idea what I'm doing wrong here or if I'm missing any special makefile syntax rules?
Asked by karpfen
(155 rep)
Feb 17, 2021, 10:29 AM
Last activity: Dec 9, 2021, 05:25 AM
Last activity: Dec 9, 2021, 05:25 AM