Trying to keep spaces in the variable for read with the \
.
$ echo "Drag folder to be copied to terminal and press ENTER."
$ read FILE
/Users/UserName/Desktop/Folder\ With\ Spaces\ In\ it
$ echo "$FILE"
/Users/UserName/Desktop/Folder With Spaces In it
The \
have been removed. I need them to remain as it will be used later in copy. Example.
$ cp -R $FILE /Volumes/USBName
I have played with different quotation marks and looked around but nothing has worked for me so far. I may have to change the IFS, not sure?
cp -R "$FILE" …
, same as when you usedecho
– Gilles 'SO- stop being evil' Dec 16 '15 at 01:35read -r
? – steeldriver Dec 16 '15 at 01:45cp -R "$FILE"
needs to have a variable with no spurious backslashes — whereascp -R $FILE
would require more than backslashes to work reliably), but even if it was, the duplicate also discussesread -r
. – Gilles 'SO- stop being evil' Dec 16 '15 at 01:57echo
was just to check. – Phil Dec 16 '15 at 03:04