-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Arrays concept part 2 #729
Conversation
echo "${myarray[*]}" | ||
``` | ||
|
||
You are required to enclose the expansion in double quotes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no actual "requirement" as much as a "should" to avoid glob expansion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requirement is that the concatenate behaviour only applies when the expansion is quoted. Otherwise you get word splitting.
In the manual:
If the word is double-quoted,
${name[*]}
expands to a single word with the value of each array member separated by the first character of theIFS
variable,
# => "one:two:three:four" | ||
``` | ||
|
||
Localizing `IFS` in the function means we don't have to save the old value and restore it back to it's previous value in the global scope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW a subshell is a (simpler?) alternative.
array=(one two three)
( IFS=,; echo "${array[*]}"; )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add it
set -- one two three | ||
set -- "$@" four | ||
|
||
for item in "$@"; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW you can also omit the in "$@"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but let's be explicit
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
No description provided.