2

I am writing a bash script to copy/move a folder called "folder" to a directory that already contains "folder" and I would like the contents to be merged.

I am attempting to use a solution from this question:

Merging folders with mv?

cp -rl source/folder destination
rm -r source/folder

If i type the first line in the terminal, source "folder" and destination "folder" are merged as expected.

However, When i run the script with the line in it, instead of merging the folders the destination now contains two folders; "folder" and "blank", where "blank" has the contents of the source "folder" in it.

  • What do you mean by "blank named folder"? The content of source/folder was not copied to destination/folder? – Freddy Nov 03 '19 at 01:46
  • After i run the script, destination now contains two folders; "folder" and "blank", where "blank" has the contents of the source "folder" in it. – puyanera Nov 03 '19 at 01:51
  • are you using variables to hold the source and destination directory names? 2. if so, are you double-quoting the variables when you use them (i.e. cp "$source" "$destination" rather than cp $source $destination - the latter, without the double-quotes, will fail in all sorts of cases that the former, with quotes, will handle without problem). see Why does my shell script choke on whitespace or other special characters?
  • – cas Nov 03 '19 at 01:52
  • @cas It's a very short script so currently the source and destination are hard coded: cp -rl /volume1/Sync/TVSync/* /volume1/Sync/TempSync/ – puyanera Nov 03 '19 at 01:56
  • ok, so not a whitespace issue then. what do you mean by "blank named folder"? – cas Nov 03 '19 at 02:08
  • @cas when i type the first line in the terminal, source "folder" and destination "folder" are merged. When i run the script with the line in it, instead of merging the folders the destination now contains two folders; "folder" and "blank", where "blank" has the contents of the source "folder" in it. – puyanera Nov 03 '19 at 10:55