$() Command Substitution in Bash vs in Zsh

Command Line
Zsh
Bash
$() concatenates the results into one single line in bash, but not in zsh.
Author

Ziyue Li

Published

January 3, 2023

A simple learning today: when using $() in Bash, it concatenates the outputs into one single line, while in Zsh, it does not seem to do so.

In bash

files=$(ls)
echo $files

outputs something like

file1.md file2.md file3.md

But when the same commands are executed in Zsh, I got

file1.md
file2.md
file3.md

with the line breaks preserved.