On 5/2/24 15:59, jeremy ardley wrote:
I have a need to get the full path of a file that has spaces in its
name to use as a program argument
e.g.
jeremy@client:~$ ls -l name\ with\ spaces
-rw-r--r-- 1 jeremy jeremy 0 May 3 06:51 'name with spaces'
jeremy@client:~$ realpath name\ with\ spaces
/home/jeremy/name with spaces
The spaces without quotes cause problems with subsequent processing.
Can realpath or other utility return a quoted pathname?
Perhaps Perl and the module String::ShellQuote ?
2024-05-02 18:50:28 dpchrist@laalaa ~
$ touch "name with spaces"
2024-05-02 18:50:45 dpchrist@laalaa ~
$ touch "name with\nnewline"
2024-05-02 19:06:01 dpchrist@laalaa ~
$ perl -MString::ShellQuote -e 'print shell_quote(@ARGV), "\n"' name*
'name with spaces' 'name with\nnewline'
David