Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Cannot reproduce. In the second example, the $(...) command substitution sees only the indexes (a list of numbers separated by newlines), because of the cut -d' ' -f1 after the sort. This could be easily demonstrated by a tee /dev/tty at the end of the $(...). Commented Nov 19, 2018 at 12:19
  • Sorry, my bad, I missed the cut. Commented Nov 19, 2018 at 13:19
  • @Isaac There's no need to quote the ${!in[@]} or ${#in[i]}/$i variable expansions because they only contain digits which are not subject to glob expansion and the unset IFS will reset the IFS to space, tab, newline. In fact, quoting them would be harmful, because it will give the false impression that such quoting is useful and effective, and that the setting of IFS and/or filtering the output of sort in the second example could be safely done away with. Commented Nov 21, 2018 at 15:41
  • @Isaac It does NOT break if in contains "testing * here" and shopt -s nullglob is set before the loop. Commented Nov 21, 2018 at 15:45