Basic bash filename escaping question
Can someone please tell me what I have done wrong with my escaping here:
Code:
$ php -q get_vid_dimensions.php '/home/kovacs/16-Exclusive McDonald'\''s Farmville farm.flv' Code:
/home/kovacs/16-Exclusive McDonald's Farmville farm.flv |
First of all, I would put the filename in double quotes (i.e. ""). Secondly, you're not escaping all the necessary characters. As a general rule, anything that isn't a number, letter (capital/lowercase), underscore, dot, or a dash (hyphen) shouldn't go into a Linux/UNIX filename; that way you can avoid problems like this. You need to escape your spaces as well (and drop the single-quotes around your escaped apostrophe).
This would be more correct, I think: Code:
"/home/kovacs/16-Exclusive\ McDonald\'s\ Farmville\ farm.flv" |
Unfortunately I have no control over the filename. The reason I put the filename in single quotes is to avoid having to escape spaces. Also some of the other filenames in this batch of media have other special characters in them which would also need escaping if I were to put them in double quotes - it's easier overall to put the filenames in single quotes in this instance.
The problem is with the escape sequence used to escape a single quote inside a filename that is encapsulated by single quotes. From the reading I've been doing, it's not enough to use a single backslash, eg. Code:
'/home/kovacs/16-Exclusive McDonald\'s Farmville farm.flv' Code:
'/home/kovacs/16-Exclusive McDonald'\''s Farmville farm.flv' |
Quote:
Perhaps this would work: Code:
"'/home/kovacs/16-Exclusive McDonald'\\''s Farmville farm.flv'" |
Indeed, that error is not bash complaining, but the php parser. Bash parses the string, the resultant string then is passed to php:
Code:
# echo '/home/kovacs/16-Exclusive McDonald'\''s Farmville farm.flv' Code:
# echo "'/home/kovacs/16-Exclusive McDonald\'s Farmville farm.flv'" |
All times are GMT -5. The time now is 03:48 PM. |