エコーを使用して*(アスタリスク)値を印刷することはできません。

エコーを使用して*(アスタリスク)値を印刷することはできません。

私は持っている、

私.sh

while IFS= read -r line ; do
v1="$line";
t1=`echo $line | awk -F= '{print $2}'`
echo "$t1"
done < $1

サンプル.txt

say=hello
test=0 0/15 * * * ?
logs=valuelogs

出力:

[root@centos gen]# ./my.sh test.txt
hello
0 0/15 hello.txt 2.txt tmp.log my.sh sample.txt test.sh test.txt hello.txt 
2.txt tmp.log my.sh sample.txt test.sh test.txt hello.txt 2.txt tmp.log 
my.sh sample.txt test.sh test.txt ?
valuelogs

ここでは、echo *現在のディレクトリのファイルのリストを出力として提供する&などのコマンドの実行により、誤った出力が表示されます。

同じ代替ソリューションはありますか?

ベストアンサー1

問題はecho $line最後の引用符にあります。ワイルドカード拡張を防ぐための二重引用符変数:

t1=`echo "$line" | awk -F= '{print $2}'`

おすすめ記事