gpt4 book ai didi

ubuntu - ifeq 不比较两个变量

转载 作者:行者123 更新时间:2023-12-04 19:00:10 25 4
gpt4 key购买 nike

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

最佳答案

这是一个应该可以工作的makefile(不,这次是真的:-)我实际上测试了这个:)

desktop:=$(shell xdg-user-dir DESKTOP)
desktopVar:=${HOME}/Área de Trabalho #note: using _MAKE_ variable ${HOME} here

$(info desktop: [${desktop}])
$(info desktopVar: [${desktopVar}])

# note: using double quotes around ifeq arguments -- not required
# here, but it's good practice:
# also note: this is not inside of a recipe, so it's done by the
# makefile at parse time

ifneq ("${desktop}","${desktopVar}")
$(info changing desktop)
desktop:=${HOME}/Área de Trabalho
endif


$(info desktop: [${desktop}])
$(info desktopVar: [${desktopVar}])

all:
@echo running $@

输出:
scripts> make -f test.mk
desktop: [/users/foo/Desktop]
desktopVar: [/users/foo/Área de Trabalho ]
changing desktop
desktop: [/users/foo/Área de Trabalho]
desktopVar: [/users/foo/Área de Trabalho ]
running all

关于ubuntu - ifeq 不比较两个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59828729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com