Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String Makefile-像Bash这样的字符串操作_String_Bash_Makefile - Fatal编程技术网

String Makefile-像Bash这样的字符串操作

String Makefile-像Bash这样的字符串操作,string,bash,makefile,String,Bash,Makefile,我正试图从给定路径中提取文件名。 例如,“folder1/folder2/file.extension”必须给出“file” 在bash中,我将使用: file_path=$1 filename="${file##*/}" # with extension article_name="${filename%.*}" # our desired result 在一个makefile中,我在一个小时后非常接近,但它就是不起作用。我正在使用GNU Make 4.1 这是我尝试的最后一个解决方

我正试图从给定路径中提取文件名。 例如,“folder1/folder2/file.extension”必须给出“file”

在bash中,我将使用:

file_path=$1
filename="${file##*/}"   # with extension
article_name="${filename%.*}"   # our desired result
在一个makefile中,我在一个小时后非常接近,但它就是不起作用。我正在使用GNU Make 4.1

这是我尝试的最后一个解决方案:

command :=  f=$(file)\; echo '$$$$'"{f\#\#*/}"
result := $(shell $(CMD))
通过手动给出
file=“folder/f.ext”
,我得到:
command=f=文件夹/f.e;echo$${f##*/}
result=5200{f###*/}


你能告诉我该怎么做才能纠正这个问题并得到想要的结果吗

此类操作最好使用内置功能实现,请参阅。就你而言:

$(basename $(notdir $(yourFileNameVariable)))

$(basename$(notdir$(file)))
可能是您所需要的。也许可以更清楚地强调,GNU Make附带了优秀的文档。但是+1