I am currently writing a bash script and I have obtained a list of file locations. However I have notice that some file locations have spaces in the file name such as eg. : /1 2 3.txt Such files affects the use of commands such as cp in my case. Using "" and escaping it results in a space after the "". For e.g: " /1 2 3.txt" with a space in front of the file location, i obtained an error stating "cp: cannot stat ` /1 2 3.txt': No Such file or directory ". Is there any other method to quote a file location with "" so that the cp command can be used?
Copy all files containing spaces inside filenames in the new files with the same name containing underscores instead of spaces from the current directory:
See BashFAQ 20 on how to handle filenames safely.