When I use
cp -R inputFolder outputFolder
the result is context-dependent:
- if
outputFolderdoes not exist, it will be created, and the cloned folder path will beoutputFolder. - if
outputFolderexists, then the clone created will beoutputFolder/inputFolder
This is horrible, because I want to create some installation script, and if the user runs it twice by mistake, he will have outputFolder created the first time, then on the second run all the stuff will be created once again in outputFolder/inputFolder.
- I want always the first behavior: create a clone next to the original (as a sibling).
- I want to use
cpto be portable (e.g. MINGW does not haversyncshipped) - I checked
cp -R --parentsbut this recreates the path all the way up the directory tree (so the clone will not beoutputFolderbutsome/path/outputFolder) --remove-destinationor--updatein case 2 do not change anything, still things are copied intooutputFolder/inputFolder
Is there a way to do this without first checking for existence of the outputFolder (if folder does not exist then...) or using rm -rf outputFolder?
What is the agreed, portable UNIX way of doing that?