1
There are occasions when you are working with files and folders that contain spaces in them. The problem is any time you try and pipe files / folders containing whitespace to another command-line program, the files / folders containing whitespace are interpreted as separate arguments rather than as a single argument. For example, consider the following directory tree:
Folder With Spaces
Folder With Spaces/FolderWithoutSpaces
Folder With Spaces/FolderWithoutSpaces/file with spaces.txt
FolderWithoutSpaces
FolderWithoutSpaces/fileWithoutSpaces.txt
If you try and run a shell command such as "grep 'some text' $(find . -type f)", you'll get the following output:
grep: ./Folder: No such file or directory
grep: With: No such file or directory
grep: Spaces/FolderWithoutSpaces/file: No such file or directory
grep: with: No such file or directory
grep: spaces.txt: No such file or directory
The big question is, how do you pipe files / folders that have whitespace in them as arguments to a command line program?
Actually, putting the
{}
in quotes has nothing to do with handling names that have spaces in them. – G-Man Says 'Reinstate Monica' – 2015-06-20T22:36:31.550I use -exec on a routine basis, but for some reason it never occurred to me to simply put quotation marks around the brackets! – rmiesen – 2013-06-29T05:53:42.720