【发布时间】:2020-01-20 18:01:44
【问题描述】:
ifeq 不比较两个变量
我正在制作一个程序来将文件移动到桌面,与操作系统中选择的语言无关。在葡萄牙语中,桌面文件夹称为“Área de trabalho”。由于“Área de Trabalho”是三个分开的单词,所以在写目录的时候需要加上单引号('Área de Trabalho'),否则命令会出错。
mv Minesweeper $HOME/Área de Trabalho/ #command
mv: target 'Trabalho/' is not a directory #Error
我正在使用这个命令来获取用户的桌面文件夹的目录:
xdg-user-dir DESKTOP
如果目录等于主目录加上“/Área de Trabalho”,我想改变
代码如下:
desktop=$(shell xdg-user-dir DESKTOP) # I'm using this command to get the directory of the desktop folder of the user
desktopVar="$$HOME/Área de Trabalho" # And if the directory is equals to the home directory plus "/Área de Trabalho"
move:
ifeq (${desktop},${desktopVar})
desktop=${HOME}/'Área de Trabalho' # I want to change the directory to ${HOME} plus "/'Área de Trabalho'", so the command doesn't results in error
@echo yes
endif
@echo ${desktopVar}
@echo ${desktop}
但是 ifeq 表示两个变量是相等的并且不会改变任何东西。
这是输出:
/home/daniel/Área de Trabalho
/home/daniel/Área de Trabalho
【问题讨论】:
-
规则 1:永远不要在你的配方行中添加
@,直到你的整个 makefile 完全工作(甚至可能不是这样)。规则 2:永远不要使用配方或 shell 来打印 make 变量,因为 shell 会解释内容并可能在打印结果之前更改结果。始终使用 make 的$(info ...)函数,这样您就可以准确地看到 make 看到的内容。