bash Word Unexpected (expecting ")") 与 Makefile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10241093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:05:34  来源:igfitidea点击:

Word Unexpected (expecting ")") with Makefile

bashmakefileless-unix

提问by Wuzseen

I'm making a makefile and I'm working on a target with no dependencies that checks to see if a file named README exists in the current directory and if it does, read it using less or else exit quitely: give no errors whatsoever--the command to run the target should print nothing to console if this is the case.

我正在制作一个 makefile 并且我正在处理一个没有依赖项的目标,该目标检查当前目录中是否存在名为 README 的文件,如果存在,则使用 less 读取它或完全退出:不要出现任何错误- - 在这种情况下,运行目标的命令不应向控制台打印任何内容。

I've tried a couple different ways but nothing really seems to work (PAGER is simply a var equal to less):

我尝试了几种不同的方法,但似乎没有任何效果(PAGER 只是一个等于 less 的 var):

read :
   ifneq ("$(wildcard README)","")
      -@$(PAGER) README
   endif

And also with this code

还有这个代码

read :
   -@for file in *;\
   do \
       if [ ${file} == "README" ]; then\
           $(PAGER) "README" ;\
       fi;\
   done

With the first chunk I keep getting an error akin to /bin/sh: Syntax error: word unexpected (expecting ")") and for the life of me I just don't get what it's saying. I certainly don't think there's a syntax error, perhaps I'm misusing make.

对于第一个块,我不断收到类似于 /bin/sh: Syntax error: word unexpected (expecting ")") 的错误,而在我的一生中,我只是不明白它在说什么。我当然不认为有语法错误,也许我在滥用 make。

For the latter code I get an unexpected operator error for the ==.

对于后面的代码,我收到了一个意外的 == 操作符错误。

I've also tried simpler things like these two single liner solutions but get similar errors:

我也尝试过更简单的事情,比如这两个单线解决方案,但得到了类似的错误:

-@test -a README && less README
-@[ -a README ] && less README

Any help would be greatly appreciated.

任何帮助将不胜感激。

EDIT: I was digging further and saw something promising and explicitly setting my shell to /bin/bash (SHELL := /bin/bash) yet no dice.

编辑:我正在进一步挖掘,看到了一些有希望的东西,并明确地将我的 shell 设置为 /bin/bash (SHELL := /bin/bash) 但没有骰子。

采纳答案by Beta

read:
        @if [ -e README ]; then less README; fi

回答by npclaudiu

You should try to extract your shell code in separate *.sh files so that you can specify them as commands in your makefile (and make sure that the *.sh files are executable).

您应该尝试在单独的 *.sh 文件中提取您的 shell 代码,以便您可以在 makefile 中将它们指定为命令(并确保 *.sh 文件是可执行的)。