Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign absolute/relative path to string variable in CLI #126

Open
mateusffreitas opened this issue Mar 9, 2021 · 4 comments
Open

Assign absolute/relative path to string variable in CLI #126

mateusffreitas opened this issue Mar 9, 2021 · 4 comments

Comments

@mateusffreitas
Copy link

mateusffreitas commented Mar 9, 2021

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.

@marshallward
Copy link
Owner

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
Copy link
Owner

Nested quotes also seem to work:

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

@mateusffreitas
Copy link
Author

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

@marshallward
Copy link
Owner

marshallward commented Mar 9, 2021

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.

zmoon added a commit to noaa-oar-arl/canopy-app that referenced this issue Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants