Skip to content

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

Description

@guw

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions