下面的数组中的星号在分配给数组时会扩展到文件列表中。
u='*','john'
IFS=$',';q=($u)
for j in "${!q[@]}"
do
echo "drop user ${q[j]}"
done
输出为:
drop user abc
drop user test.sh
drop user test1.sh
drop user john
我打算得到的是:
drop user *
drop user john
我如何摆脱星号?
答案 0 :(得分:3)
您可以使用以下脚本:
u='*,john'
# read comma delimited string into an array
IFS=, read -ra q <<< "$u"
# check content of array q
declare -p q
# loop through array q
for j in "${q[@]}"
do
echo "drop user $j"
done
输出:
declare -a q=([0]="*" [1]="john")
drop user *
drop user john