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

Default="${HOME}/..." not properly expanded #143

Open
guw opened this issue Feb 24, 2021 · 3 comments
Open

Default="${HOME}/..." not properly expanded #143

guw opened this issue Feb 24, 2021 · 3 comments

Comments

@guw
Copy link

guw commented Feb 24, 2021

I might be doing something wrong but it looks like variable expansion is not working for default values in my sell environment (Big Sur, Fish shell).

I have

  -s --some-dir [arg]       Location of directory. Default="${HOME}/some/dir"

Further down I have:

debug "arg_s: ${arg_s}"
debug "HOME: ${HOME}"

[[ -d "${arg_s:-}" ]] || {
    error     "No directory found at: ${arg_s:-}"
    exit 1
}

Here is my output:

$  LOG_LEVEL=7  ./myscript -- test

[    debug] arg_s: ${HOME}/some/dir
[    debug] HOME: /Users/myusername
[    error] No directory found at: ${HOME}/some/dir

The interesting thing is that it really prints out ${HOME} instead of /Users/myusername.
However, when I use ${HOME} directly in the script it works.

One observation from my shell:

$ echo "${HOME}"
fish: Variables cannot be bracketed. In fish, please use "$HOME".
echo "${HOME}"
       ^

$ echo "$HOME"
/Users/myusername
@mstreuhofer
Copy link
Collaborator

Well I can tell you that it has nothing to do with your shell. I tested it with BASH and the same happens. The code parsing the usage string into getopts arguments is not sophisticated enough or maybe it was never intended to support that. But don't let me stop you from scratching that itch of yours. We all would certainly welcome this new feature. :-)

@guw
Copy link
Author

guw commented Feb 25, 2021

Oh, so I read the documentation wrong. Sorry about that. When reading

# you can use bash variables to work around this (so use ${HOME} instead)
I assumed it would work in the default.

@mstreuhofer
Copy link
Collaborator

Nice catch. Might be that this comment is from a time before the big rewrite of the usage string parsing. Of course this means that either the code is wrong or the comment.

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