|Think about Loose Coupling|
Re^2: system(cp filenamewithspaces newplace/newname)by afoken (Chancellor)
|on May 13, 2009 at 06:34 UTC||Need Help??|
Double quotes on a bourne shell are subject to shell interpolation. Strange filenames will bite you:
The shell invoked (typically /bin/sh) will see the following command line:cp "mostly-harmless.txt" "$(rm -rf /)"
Before executing cp, the shell must first evaluate "rm -rf /", as its stdout should be passed as second argument to cp.
The best way to use system is not to mess with the shell at all, i.e. to use the system LIST variant or a perl build-in. In this case, CPAN has File::Copy which handles file copying inside perl, automatically using the most efficient implementation available (system API if present, fall back to open-read-write-close), and without any quoting problems or slow sub-process invokations.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)