带有GNU Shell函数的意外标记`('附近的语法错误 [英] syntax error near unexpected token `(' with GNU shell function
问题描述
我想在我的makefile文件中确定Intel Fortran编译器的版本,所以我使用了如下的 GNU shell
函数添加了一些脚本进行测试,
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)
如果您复制上面显示的那些代码行,请确保在 echo
命令之前有一个选项卡.
If you copy those code lines shown above, make sure there is a tab before the echo
command.
这给了我一些错误
/bin/sh: -c: line 0: syntax error near unexpected token `('
当我运行命令 ifort --version
或 ifort --version |grep ^ ifort
在终端中,它给出了正确的结果,并且没有发生错误.
When I ran the command ifort --version
or ifort --version | grep ^ifort
in a terminal, it gave proper result and no error occurred.
我的系统:64位CentOS 7
My system: 64-bit CentOS 7
赞赏任何纠正建议.
添加更多输出详细信息:
Add more output details:
使用 VERIFORT
的 grep
版本, make
命令产生以下结果,
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
[已解决]
事实证明,这是@MadScientist提到的 echo
使用问题
It turns out to be an echo
-usage problem as mentioned by @MadScientist
我认为您在打印时需要引用
VERIFORT
变量的值,以便外壳程序不解释特殊字符.
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.
引用 VERIFORT
变量产生以下结果( grep
版本)
Quoting the VERIFORT
variable produced the following result (the grep
version)
echo 'ifort (IFORT) 18.0.2 20180210'
ifort (IFORT) 18.0.2 20180210
并且没有发生错误.
我还通过在终端中使用 echo
对其进行了测试
I also tested it by using echo
in a terminal
echo ifort (IFORT) 18.0.2 20180210
哪个生成了相同的错误
bash: syntax error near unexpected token `('
推荐答案
似乎您没有显示 make
命令的完整输出.我认为在此错误消息之前, make
打印了 echo
行(除非您显示给我们的makefile实际上不是您调用的内容,并且您的实际makefile中添加了@
在回显之前...,在这种情况下,应在调试时将其删除).如果您向我们展示了该输出是什么,那么将会更清楚问题出在哪里.同样,当您从命令行运行 ifort --version
命令时,您没有显示它的输出是什么,但是我认为它可能包含括号.
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.
我认为您在打印时需要引用 VERIFORT
变量的值,以便外壳程序不解释任何特殊字符:
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)'
这篇关于带有GNU Shell函数的意外标记`('附近的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!