I wanted to determine the version of the Intel Fortran compiler in my makefile, so I added some script using GNU shell
function as below for testing,
VERIFORT := $(shell ifort --version)
#VERIFORT := $(shell ifort --version | grep ^ifort) # error occurred too
.PHONY: test
test:
echo $(VERIFORT)
If you copy those code lines shown above, make sure there is a tab before the echo
command.
which gives me some errors
/bin/sh: -c: line 0: syntax error near unexpected token `('
When I ran the command ifort --version
or ifort --version | grep ^ifort
in a terminal, it gave proper result and no error occurred.
My system: 64-bit CentOS 7
Appreciate any correction suggestions.
[EDIT]
Add more output details:
With the grep
version of VERIFORT
, the make
command produced the following result,
echo ifort (IFORT) 18.0.2 20180210
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `echo ifort (IFORT) 18.0.2 20180210'
make: *** [test] Error 1
[SOLVED]
It turns out to be an echo
-usage problem as mentioned by @MadScientist
I think you need to quote the value of the
VERIFORT
variable when you print it, so that the shell doesn't interpret special characters.
Quoting the VERIFORT
variable produced the following result (the grep
version)
echo 'ifort (IFORT) 18.0.2 20180210'
ifort (IFORT) 18.0.2 20180210
and no error occurred.
I also tested it by using echo
in a terminal
echo ifort (IFORT) 18.0.2 20180210
Which generated the same error
bash: syntax error near unexpected token `('
It seems you didn't show the complete output of the make
command. I think before this error message, make
printed an echo
line (unless the makefile you showed us isn't actually what you invoked, and your actual makefile adds a @
before the echo... in which case you should remove it while you debug). If you'd shown us what that output was it would be more clear what the problem is. Also you didn't show what the output of the ifort --version
command is when you run it from the command line, but I think it probably contains parentheses.
I think you need to quote the value of the VERIFORT
variable when you print it, so that the shell doesn't interpret any special characters:
test:
echo '$(VERIFORT)'