in reply to Ubuntu File Names with spaces and special characters
The problem arises because you quote AND escape (\). Choose one or the other.
Secondly, the ~ character has meaning within the shell. Perl, I guess, sees ~ as part of the filename and does not expand it to mean home-dir as the unix shell would. So avoid using linux shell shortcuts in a Perl expression.
This sort of quoting should work but notice that I removed the tilde, you need to find a way to substitute it with a Perl equivalent, perhaps $ENV{HOME}? :
my $BibleFullNames = $ENV{HOME}."/Aoo/01-Writer/Other/UMC\~\~\ Change +water/\[01\]\ Team\ Leader-\ Worship\ Service/Bible\ Books,\ Full\ Na +mes.txt"; if (!(-e $BibleFullNames)) { Log2die("**Fatal err, can't find Bible names file (\"$BibleFullNames +\")"); }
EDIT: you may find this useful: Re^3: quoting/escaping file names, it mentions String::ShellQuote which will do all the dirty work for you.
EDIT2: the more I think about it the more I am convinced that you SHOULD use a module for escaping your filenames (String::ShellQuote works only for Bourne shell, I would search for the equivalent of DBI's quote()), and also use a module to handle the path separator (/ or \\ or // or whatever). Then your Perl script will be portable and work in the 2 OS without need to further change this or that. For example, here is how I construct paths in a portable way: use File::Spec; my $path = File::Spec->catfile('a', 'b', 'c');.
EDIT3(24h+): the difference between $x = "\ "; $y = '\ '; is that $x will contain a space. Whereas $y will contain a backslash followed by a space. Perl single quotes do not interpolate their contents, unlike the double quotes (escaped characters and also variables). In $y, the backslash is kept in the string and is passed on to anyone who consumes it, shell included. So, if you want to pass a filename to the shell for processing, as in for example system("ls $file") then $file should contain literal backslashes to meta-escape any space in there, as in $y. That or system("ls '$file'") (notice the single quotes) when $file is somwething like $x and it does not contain any backslashes. If you do -e $file then $file should be something like $x. Because if there is a backslash character in $file which does not serve to escape any following character then perl interprets it as part of the filename. So there are some queer characters which in the 70's were marginalised and discriminated against but now have rightly claimed equal treatment being part of the ASCII-kind and all. Still, old software demands that these characters are escaped. Escaping takes place in many levels simply because one program passes on parameters to another, a single backslash is lost from one passing to the next. So Perl passes on parameter to the shell (e.g. via a system ls)? Then make sure that parameter includes backslashes as means to escape funny characters. Does that system calls yet another command which calls another command? Then you may have to escape twice. And so on. I am definetely not the expert in escaping though and I may have missed some crucial points.
bw, bliako
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ubuntu File Names with spaces and special characters
by Lotus1 (Vicar) on Feb 27, 2019 at 15:56 UTC | |
by bliako (Abbot) on Feb 28, 2019 at 11:38 UTC | |
|
Re^2: Ubuntu File Names with spaces and special characters
by EigenFunctions (Beadle) on Feb 28, 2019 at 13:11 UTC | |
by haukex (Archbishop) on Mar 01, 2019 at 08:35 UTC |