bash mkdir and cp error on variable path "cannot create directory : No such file or directory"

octosquidopus picture octosquidopus · Aug 19, 2011 · Viewed 14.5k times · Source

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?

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

Answer

Lars picture Lars · Aug 19, 2011

mkdir -p $target will create the path with all necessary subpaths.