I write scripts in tcsh (sorry, not bash) and programs in Perl (in the past, I've written a lot in "C"). In both cases (tcsh and Perl), I have problems with filenames that contain special characters. I use (){}[]!# in most of my filenames and folder names, some of which came from the old days of windoz. My laptops run either Ubuntu or Debian and I use nautilus to access files and it understands these files and folder.

A Perl snippet as an example of the problem:

use String::ShellQuote; # this package almost n +ever works my $Temp = shell_quote_best_effort('BulletinV3, 1 Montana 20xx-xx-xx ( +print).pdf_FN_TEMPLATE'); if (-e $Temp) { `zenity --width 300 --info --text 'DBG> Got it!'`; } else { `zenity --width 300 --error --text 'DBG> Nope, not found!'`; # thi +s is what I get all the time } $rc = rename("BulletinV3, 1 Montana 20xx-xx-xx (print).pdf_FN_TEMPLATE +", "BulletinV3, 1 Montana $SundayDate (print).pdf_FN_TEMPLAT +E"); if($rc == 1) { $ExtTypes{'pdf_FN_TEMPLATE'}++; } else { `zenity --title \"Rename problem\" --width 400 --error --text \"Fi +le rename error (\\\"$!\\\"; \\\"BulletinV3, 1 Montana 20xx-xx-xx (pr +int).pdf_FN_TEMPLATE\\\")\"`; }

I know the file is there, I can see it, I can show it with ls (on the command-line), but the Perl program does not. I've tried all manner of quoting with backslashes, single and double quotes etc. I've tried using back-ticks with Linux 'mv' commands instead of rename() but in all the cases, nothing works. I've been plagued with this problem for years and, sometimes, I can find unique ways to deal with it. I'd like a way that I can use for all situations (it seems, nautilus has a solution that works).

Any help would be greatly appreciated.

Thanks,
  EigenFunctions
  OpSys: Ubuntu 18.04; Perl: Perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi (with 71 registered patches)


In reply to Problems with special characters in Linux file names by EigenFunctions

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.