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

Re: realpath quoting



In days of yore (Fri, 03 May 2024), jeremy ardley thus quoth: 
> 
> On 3/5/24 19:06, Greg Wooledge wrote:
> > I would suggest that if you need to use a debugger to track down a bug
> > in your program, you should use filenames that don't require quoting
> > when you set up your tests.
> 
> 1970's style static test cases are not relevant here.
> 
> In the real world...  I download files generated by another system that
> are constantly changing content and with names I don't control.
> 
> My workflow is to download a new file from a remote source and then run my
> processor over it.
> 
> As a necessary consequence I need the fully quoted or escaped file name of
> the new file to feed to the processor/debugger.
> 
> I can obviously add an extra step to the process to convert the new file
> name to something acceptable before processing. However, my question was
> how to avoid that extra step by getting fully quoted filenames to process.

Encase the file-name in single or double quotes. If it contains any kind
of construct that could be expanded by the shell, single quotes.

Consider this example:

$ file=abc
$ echo "$file"
$ echo '$file'

If you copy-paste anywhere, slap single quotes around it by habit and you
will not get taken by surprise by spaces or anything the shell decide
looks like something it can evaluate or expand.

-- 
Kind regards,

/S


Reply to: