1

ディレクトリの内容を一覧表示するスクリプトを作成しようとしました。

#!/bin/bash
matched=$(ls -1 /data/ | grep $1)
echo $matched

コマンドにパラメーター-1を追加しました。このように実行すると、出力は1行になります。ls./script dir

dir1 dir2

私も試しましecho -e $matchedたが、出力は次のとおりです。

-e dir1 dir2

では、どのようにしてディレクトリをそれぞれ別々の行にリストすることができますか?

4

1 に答える 1

3

Try using double quotes around the string to be echoed:

echo "$matched"

The quotes here cause certain special characters to be preserved; see here.

Edit: See cdarke's comment for a better explanation.

于 2012-06-18T06:58:00.387 に答える