f90nml icon indicating copy to clipboard operation
f90nml copied to clipboard

Assign absolute/relative path to string variable in CLI

Open mateusffreitas opened this issue 3 years ago • 4 comments

It doesn't seem that the CLI supports the use of '/'.

Using

f90nml -v DIR='./path/to/dir' -v ODIR='/path/to/dir' input

will make DIR have the value '.', and ODIR empty. Escaping doesn't work either.

mateusffreitas avatar Mar 09 '21 02:03 mateusffreitas

You're right, it looks like strings in general are not being handled very well. It is trying to assign a non-delimited string, something like this:

&test_nml dir=./path/to/dir /

and the slashes are being interpreted as end-of-namelist tokens.

This case does seem to work for me:

f90nml -v dir=\"./path/to/dir\" -v odir=\"/path/to/dir\" input

but I admit that it's not what one would like to see. (\' also seems to work for me).

I think overall it is going to be difficult to know the best way to communicate string delimiters inside of a shell command (if at all). But something a little more intuitive is needed here.

marshallward avatar Mar 09 '21 02:03 marshallward

Nested quotes also seem to work:

f90nml -v dir='"./path/to/dir\"' -v odir="'/path/to/dir'" input

marshallward avatar Mar 09 '21 02:03 marshallward

I see. I thought only of escaping the slashes inside the quotes. Both ways work indeed.

mateusffreitas avatar Mar 09 '21 02:03 mateusffreitas

This reminds me on an inherent issue with namelists, where the default behavior is to write a strings without delimiters. For certain strings, such as a filepath, it will tend to produce a very flawed namelist.

I drafted a proposal to address the issue, but it didn't generate very much interest.


As for the issue here, I think it might be possible to change the behavior to be a bit more intuitive. Tokens in shell commands are often already assumed to be strings, to the point where putting delimiters around them is redundant.

There would be some interesting special cases:

  • Does v=123give the number or the string?
  • How to handle spaces? v=a\ string? v="a string"? Or are both valid?
  • Does v=\"abc\" give abc or "abc" (i.e. are the delimiters part of the string?)

But if we defined our rules then it could at least approach something consistent with the shell's own syntax.

marshallward avatar Mar 09 '21 04:03 marshallward