Here’s a snippet of code from a shell script I have written:
for src in $(find . -type f -maxdepth 1 \! -name ${deploy} \! -name gvimrc) do src=$(basename ${src}) dest='~/.${src}' copy='${src} -> ${dest}' cp $src $dest && echo -e '${ok} ${copy}' || echo -e '${fail} ${copy}' done
For some reason, cp fails to execute. For example, in the case in which $src='bashrc', I get this error:
cp: ~/.bashrc: No such file or directory
I don’t understand why this happens, though, because obviously, ~/.bashrc is the destination, not the source, so cp shouldn’t care whether it exists or not. What exactly is going wrong?
You have escaped the ~ and so it won’t get expanded and cp doesn’t know how to do it.
With
bash should do it.