例如,我的文件包含以下内容...
set -A array
set -A test
${array[0]}=1
${array[1]}=2
${array[2]}=3
${test[0]}="Boy"
${test[1]}="Girl"
${test[2]}="Dog"
x=0
while [ $x -lt 3 ];do
print "${array[$x]}" " " "${test[$x]}"
x=$((x+1)
done
您必须手动控制列打印之间的间隔...。我想我看到的是
printf "%3s %-4s" "${array[$x]}" "${test[$x]}"
显然,它无法正常打印
1Boy
2Girl
3Dog
.................. 除非我喜欢
printf "%s %s" "${array[$x]}" " " " ${test[$x]}"
它将像我想要的那样打印出来
1 Boy
2 Girl
3 Dog