变量路径上的 bash mkdir 和 cp 错误“无法创建目录:没有这样的文件或目录”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7115160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash mkdir and cp error on variable path "cannot create directory : No such file or directory"
提问by octosquidopus
I'm trying to automate copying the content from a variable path (my camera) into a partially-user-defined path (desktop+date+event). The problem is that mkdir and cp complain saying that the directory cannot be created, but I don't understand why despite having DuckDuckGo'd for over an hour. What am I doing wrong?
我正在尝试将内容从可变路径(我的相机)自动复制到部分用户定义的路径(桌面+日期+事件)中。问题是 mkdir 和 cp 抱怨说无法创建目录,但我不明白为什么尽管 DuckDuckGo 已经运行了一个多小时。我究竟做错了什么?
echo -n "Enter event name and press [ENTER]: "
read event
sleep 0
day=`date +%Y-%m-%d`
month=`date +%Y-%m`
media="/media/F009-64A5"
source="${media}/PRIVATE/AVCHD/BDMV/STREAM/*"
target="/home/kv/Desktop/$month/$day"\_"$event"
mkdir $target
cp -pr $source $target
回答by Lars
mkdir -p $targetwill create the path with all necessary subpaths.
mkdir -p $target将创建包含所有必要子路径的路径。

