I want to be able to call the function and have the contents be interpreted as a single argument, and I want to do this in the cleanest / shortest way possible.
The cleanest and shorted way possible is to enclose your arguments around quotes to prevent word splitting and possible pathname expansion (now named filename expansion in 4.3) however there's a workaround if you only plan to run your scripts on Zsh or Bash.
In Bash, you can simply just disable word splitting with IFS=. You can also disable pathname expansion with shopt -s -o noglob or set -f. With sensible application this can actually be a good practice for advanced scripters if they know what they're doing.
Of course with word splitting disabled you can no longer do for x in $something; do. But that doesn't matter anyway since unless pathname expansion is disabled, that form is not commendable. You can however use IFS=<separators> read -rd '' -a array <<< "$something"; for x in "${array[@]}"; do as a better alternative.
With pathname expansion disabled you can still use compgen (applies extglob and dotglob as well when enabeld):
readarray -t files < <(compgen -G '*')
Or
IFS='\n' read -rd '' -a files < <(compgen -G '*')
But that's not going to be perfect enough for filenames with newlines as conservative parties would say. So you can use a generator function:
function generate {
local RESTORE=$(shopt -p -o noglob) IFS=
shopt -u -o noglob
__=($1)
eval "$RESTORE"
}
generate '*'
for file in "${__[@]}"; do
:
done
This is good if you don't do pathname expansion often.
And there's one last thing: "$*" and "${var[*]}" would no longer expand with space as a separator. So like when having a custom separator, merging arrays to a string is easy with eval:
IFS=' ' eval 'merged="${var[*]}"'
And all of these can be done safely by inserting the rules at the beginning of the script.
[ -n "$BASH_VERSION" ] || exit ## You may use a block instead and insert a message if you like.
[[ BASH_VERSINFO -ge 4 ]] || exit ## If you need `readarray` or other 4.0+ stuffs.
IFS=
shopt -s -o noglob
With that you can now safely use do_something $x.
Now watch how these ideas go to posing online wikis later ;)
Like I said, this is for advanced users. People who care much about promotion and denounce possibly misleading practices to newbies would probably not want this. So as explicitly noted, stay away from this if you have an opposing approach or perception. No need to bash with "obvious" remarks.