尝试mkdir时出现Shell变量问题 [英] Shell variable issue when trying to mkdir
本文介绍了尝试mkdir时出现Shell变量问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何想法这段代码有什么问题吗?
Any ideas what is wrong with this code?
CLIENT_BUILD_DIR="~/Desktop/TempDir/"
if [ ! -d $CLIENT_BUILD_DIR ]
then
{
mkdir $CLIENT_BUILD_DIR
}
fi
我收到错误消息:mkdir:〜/Desktop:没有这样的文件或目录.
I get the error: mkdir: ~/Desktop: No such file or directory.
很明显,目录存在,并且如果我将变量替换为〜/Desktop/TempDir/
Obviously the directory is there and the script works if I replace the variable with ~/Desktop/TempDir/
推荐答案
引号可防止〜的扩展.
The quotes prevent the expansion of ~.
使用:
CLIENT_BUILD_DIR=~/Desktop/TempDir/
if [ ! -d "$CLIENT_BUILD_DIR" ]
then mkdir "$CLIENT_BUILD_DIR"
fi
这篇关于尝试mkdir时出现Shell变量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文