Using the bash shell in the Mac OS X terminal, I want to put inside a variable all the filenames in the current directory, with one name per line (basically, the output of ls -1). However, if I do:
var=$(ls -1)
echo $var
Variable 'var' contains contains all the filenames, but on a single line, separated with spaces. How can I fix this and get what I want. More generally, what is the reason of this behavior? What is going on during the expansion of ls -1?
I realize that I could put what I want inside a file by doing the following, but I would rather achieve the same result with a variable.
ls -1 > var
Thanks in advance.