You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Definition:
Test case:
Result:
Reminder what word splitting usually does:
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:
gives you