Say, for example, I have the following array:
files=( "foo" "bar" "baz fizzle" )
I want to pipe the contents of this array through a command, say sort
, as though each element where a line in a file. Sure, I could write the array to a temporary file, then use the temporary file as input to sort
, but I'd like to avoid using a temporary file if possible.
If "bar fizzle"
didn't have that space character, I could do something like this:
echo ${files[@]} | tr ' ' '\012' | sort
Any ideas? Thanks!