[英]Bash multiline echo
I tried to create a script to list the contents of a directory: 我试图创建一个脚本来列出目录的内容:
#!/bin/bash
matched=$(ls -1 /data/ | grep $1)
echo $matched
I have added the parameter -1
to the ls
command and when executed like this ./script dir
the output is on one row: 我已经将参数
-1
添加到ls
命令中,当像这样执行时./script dir
输出在一行上:
dir1 dir2
I've also tried echo -e $matched
, but the output was: 我也试过
echo -e $matched
,但输出是:
-e dir1 dir2
So how can I list the directories each on separate line ? 那么如何在单独的行中列出每个目录呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.