0

The destination directory is a directory with spaces in the name: /opt/config/Sn Lk Now I wrote a script which moves a file from my directory to this directory, but the move fails Although the echo of the command seems to be fine

workdir=/home/mydir
destdir="'opt/config/Sn Lk"
file=Al_10.txt

destination="$destdir/$file'" echo "command = mv -v $workdir/$file $destination" mv -v $workdir/$file $destination

result:

command = mv -v /home/mydir/Al_10.txt '/opt config/Sn Lk/Al_10.txt'
mv: target ‘Lk/Al_10.txt'’ is not a directory

How should the move-command be written?

  • This is some really weird bash code. Not sure I understand this: destdir="' – Artem S. Tashkinov Dec 15 '22 at 14:57
  • @ArtemS.Tashkinov That "opening" single quote seems to be closed in the destination variable, probably in the hope to protect the spaces in the directory names. – AdminBee Dec 15 '22 at 15:04
  • 1
    Drop the literal single quotes from the variables and double-quote the variable expansions in the mv command. See also the questions and answers marked as dupes. – Kusalananda Dec 15 '22 at 15:34

0 Answers0