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

[KNOWN ISSUE] Word splitting and filename expansion should not be performed when assigning values to variables #295

Open
itislu opened this issue Mar 31, 2024 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@itislu
Copy link
Collaborator

itislu commented Mar 31, 2024

Definition:

name=[value]

Test case:

bash-5.1$ export A="  a  b  c  "
bash-5.1$ export Z=$A
bash-5.1$ export

Result:

export Z="  a  b  c  "

Reminder what word splitting usually does:

bash-5.1$ export $A
bash-5.1$ export
.
.
.
export a
export b
export c

Reference:
https://www.gnu.org/savannah-checkouts/gnu/bash/manual/html_node/Shell-Parameters.html


Explanation

Note

Thanks a lot to @gwolf-011235!
The following is directly quoted from him.

Bash has flags for its builtins, one of which is "ASSIGNMENT_BUILTIN", which indicates "This builtin takes assignment statements." - builtins.h

This flag is checked in function fix_assignment_words() which has the amusing description: "This is a hack to suppress word splitting for assignment statements given as arguments to builtins with the ASSIGNMENT_BUILTIN flag set." - execute_cmd.c

This function is called in execute_simple_command() before the words get expanded with expand_words() - execute_cmd.c

If you hide export from bash before expansion takes place you can achieve the result you were expecting:

export A="  a  b  c  "
sneaky_boy=export
$sneaky_boy Z=$A

gives you

[...]
export Z=""
export a
export b
export c
@itislu itislu added the bug Something isn't working label Mar 31, 2024
@itislu itislu added this to the Expander milestone Mar 31, 2024
itislu added a commit that referenced this issue Mar 31, 2024
Don't do wildcard expansion in heredoc content or end.

Known issues:
- #295 Word splitting and filename expansion are not performed when assigning values to env variables
- #296 In --posix mode, words after redirection operators do not undergo filename expansion if shell is not interactive
itislu added a commit that referenced this issue Apr 1, 2024
Don't do wildcard expansion in heredoc content or end.

Known issues:
- #295 Word splitting and filename expansion are not performed when assigning values to env variables
- #296 In --posix mode, words after redirection operators do not undergo filename expansion if shell is not interactive
itislu added a commit that referenced this issue Apr 1, 2024
Don't do wildcard expansion in heredoc content or end.

Known issues:
- #295 Word splitting and filename expansion are not performed when assigning values to env variables
- #296 In --posix mode, words after redirection operators do not undergo filename expansion if shell is not interactive
itislu added a commit that referenced this issue Apr 1, 2024
Don't do wildcard expansion in heredoc content or end.

Known issues:
- #295 Word splitting and filename expansion are not performed when assigning values to env variables
- #296 In --posix mode, words after redirection operators do not undergo filename expansion if shell is not interactive
itislu added a commit that referenced this issue Apr 1, 2024
Don't do wildcard expansion in heredoc content or end.

Known issues:
- #295 Word splitting and filename expansion are not performed when assigning values to env variables
- #296 In --posix mode, words after redirection operators do not undergo filename expansion if shell is not interactive
@itislu itislu changed the title [BUG] Word splitting and filename expansion are not performed when assigning values to env variables [KNOWN ISSUE] Word splitting and filename expansion are not performed when assigning values to env variables Apr 1, 2024
@itislu itislu changed the title [KNOWN ISSUE] Word splitting and filename expansion are not performed when assigning values to env variables [KNOWN ISSUE] Word splitting and filename expansion should not be performed when assigning values to env variables Jun 29, 2024
@itislu itislu changed the title [KNOWN ISSUE] Word splitting and filename expansion should not be performed when assigning values to env variables [KNOWN ISSUE] Word splitting and filename expansion should not be performed when assigning values to variables Jul 17, 2024
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
Status: Backlog
Development

No branches or pull requests

1 participant