makefile:foreach 错误
我的 makefile 中有这个,
rcFiles = .vim .vimrc .gitconfig .hgrc .screenrc .Xresources .dircolors .bashrc .ctags .bash_completion.d
install:
@$(foreach f,$(rcFiles), [ -f $(HOME)/$f ] || ln -v -s $(PWD)/$f $(HOME)/ ; )
如果 .bashrc 退出并且我尝试
make install
得到
ln: creating symbolic link `/home/user/.vim': File exists
ln: creating symbolic link `/home/user/.bash_completion.d': File exists
并且进程被中止。 为什么没有条件阻止这个问题呢?
I have this in my makefile,
rcFiles = .vim .vimrc .gitconfig .hgrc .screenrc .Xresources .dircolors .bashrc .ctags .bash_completion.d
install:
@$(foreach f,$(rcFiles), [ -f $(HOME)/$f ] || ln -v -s $(PWD)/$f $(HOME)/ ; )
if .bashrc exits and I try
make install
I get
ln: creating symbolic link `/home/user/.vim': File exists
ln: creating symbolic link `/home/user/.bash_completion.d': File exists
and the process is aborted.
why no prevented this problem the conditional?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
--force
标志使其替换现有链接如果链接已经存在,则
--no-dereference
避免为目录链接创建“子目录”链接(对于.bash_completion.d
和.vim 有用
dirs)或者
不仅检测文件 (
-f
),还检测目录。您可能想要明确检查文件和目录[ -f ... || -d ...]
。The
--force
flag makes it replace an existing linkThe
--no-dereference
avoids creating 'subdirectory' links for links to directory, if the link existed already (useful for the.bash_completion.d
and.vim
dirs)Alternatively
To not only detect files (
-f
) but also directories. You might want to explicitely check for files and directories[ -f ... || -d ... ]
.仅当
$(HOME)/$f
是(扩展为)文件时才为 true。您遇到错误的内容(.vim
和.bash_completion.d
)是目录。请尝试这样做:(双引号并不是绝对必要的,但如果
$(HOME)/$f
扩展为包含 shell 元字符的内容,它可以为您节省麻烦。)is true only if
$(HOME)/$f
is (expands to) a file. The things you're getting errors on (.vim
and.bash_completion.d
) are directories. Try this instead:(The double quotes are not strictly necessary, but will save you grief in the event that
$(HOME)/$f
were to expand to something with shell metacharacters in it.)