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

Error with multiline variable and ${VARIABLE} notation: "Expected a variable name after this $" #19

Open
9999years opened this issue Oct 14, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@9999years
Copy link

Given a file hook.sh:

export shellHook='"${DIRENV_IN_ENVRC}"
'

Then, replay . hook.sh errors:

$ replay . hook.sh
- (line 1): Expected a variable name after this $.
set --global --export shellHook \"\\$\{DIRENV_IN_ENVRC\}\"\
                                    ^
from sourcing file -
        called on line 25 of file ~/.config/fish/fundle/jorgebucaran/replay.fish/functions/replay.fish
in function 'replay' with arguments '. hook.sh'
source: Error while reading file '<stdin>'

I'm not sure what exactly causes this bug, but it seems to be the combination of a multiline variable and the braced ${VARIABLE} notation.

I assume part of this bug is from the complexity of escaping in replay.fish: first the variable contents are passed to string escape, then piped through string replace --all -- \$ \\\$, then through string replace --all -- \\n \n.

After inserting some debugging statements, it looks like this is what's sourced in fish:

set --global --export shellHook \"\\$\{DIRENV_IN_ENVRC\}\"\

And we can confirm:

$ string escape -- '"${DIRENV_IN_ENVRC}"\\n' | string replace --all -- \$ \\\$ | string replace --all -- \\n \n
\"\\$\{DIRENV_IN_ENVRC\}\"\

I'm not actually sure what the string replace --all \$ \\\$ bit is for; maybe it's relevant for other lines?

@9999years 9999years changed the title Error with multiline variable and ${VARIABLE} notation Error with multiline variable and ${VARIABLE} notation: "Expected a variable name after this $" Oct 14, 2022
@jorgebucaran jorgebucaran added the bug Something isn't working label Oct 14, 2022
9999years added a commit to 9999years/dotfiles that referenced this issue Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants