[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: realpath quoting



* 2024-05-03 06:59:37+0800, 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

> jeremy@client:~$ realpath name\ with\ spaces
> /home/jeremy/name with spaces

> Can realpath or other utility return a quoted pathname?

Tools don't need to return a shell-quoted pathname because you as a
shell programmer must do it:

    file=$(realpath ...)       # quotes not needed in variable assignment
    do_something_for "$file"   # always quote: "$file"


If you don't need variables you can just quote the "realpath" output:

    do_something_for "$(realpath ...)"

-- 
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 6965F03973F0D4CA22B9410F0F2CAE0E07608462

Attachment: signature.asc
Description: PGP signature


Reply to: