
bashシェルと同様に、echoを使用して文字列を印刷できますecho "This is a sample string"
。
パイプとして使用できるいくつかのコマンドまたは文字列の後にエコーされるいくつかのパラメータがありますか?これにより、次のような結果が出力されます。
This
is
a
sample
string
デフォルトでは、文字列を分割し、各単語を新しい行に印刷します。
答え1
$ echo "This is a * sample string" | tr ' ' '\n'
This
is
a
*
sample
string
$
答え2
Paulのコメントが正確で、ファイル名のグロービングを避ける必要があり、残りのパラメータ数のテストが簡単すぎて、Kornシェルを使用しています。
V="This is a sample * string"
set -f
set $V
while [ $# -gt 0 ]
do
echo $1
shift
done
答え3
同じもの
s="This is a sample * string"
set -f
printf "%s\n" $s