在 Bash 中打印一个 table
Print a table in Bash
我在使用 printf 函数或 echo 打印数组中的所有值以打印漂亮的 table 时遇到问题。我试过简单的,但它不是我想要的顺序。
for i in ${!R[@]}
do
printf "%-20s" ${R[i]}
printf "\n"
done
what i have
what i want
我想要什么
mteEventComment mteEventActions mteEventEnabled mteEventEntryStatus
"80 " true active
"80 " true active
"80 " true active
"80 " true active
"80 " true active
"80 " true active
我有什么
mteEventComment mteEventActions mteEventEnabled mteEventEntryStatus
"80 " "80 " "80
" "80 " "80 "
"80 " true true true
true true true active active
active active active active
script2.sh: line 64: "80: syntax error: operand expected (error token is ""80")
content of **R array**: First 6 are empty
"80 " "80 " "80 " "80 " "80 " "80 " true true true true true true active active active active active active
我有 header
printf "$header" "mteEventComment" "mteEventActions" "mteEventEnabled" "mteEventEntryStatus"
mteEventComment mteEventActions mteEventEnabled mteEventEntryStatus
在此之下,我需要我的数组以准确的顺序排列
鉴于 R 中的数据包含带有特殊字符(引号、空格)的值(和潜在的键),您想要引用它们:
for i in "${!R[@]}"
do
printf "%-20s\n" "${R[i]}"
done
我在使用 printf 函数或 echo 打印数组中的所有值以打印漂亮的 table 时遇到问题。我试过简单的,但它不是我想要的顺序。
for i in ${!R[@]}
do
printf "%-20s" ${R[i]}
printf "\n"
done
what i have what i want
我想要什么
mteEventComment mteEventActions mteEventEnabled mteEventEntryStatus
"80 " true active
"80 " true active
"80 " true active
"80 " true active
"80 " true active
"80 " true active
我有什么
mteEventComment mteEventActions mteEventEnabled mteEventEntryStatus
"80 " "80 " "80
" "80 " "80 "
"80 " true true true
true true true active active
active active active active
script2.sh: line 64: "80: syntax error: operand expected (error token is ""80")
content of **R array**: First 6 are empty
"80 " "80 " "80 " "80 " "80 " "80 " true true true true true true active active active active active active
我有 header
printf "$header" "mteEventComment" "mteEventActions" "mteEventEnabled" "mteEventEntryStatus"
mteEventComment mteEventActions mteEventEnabled mteEventEntryStatus
在此之下,我需要我的数组以准确的顺序排列
鉴于 R 中的数据包含带有特殊字符(引号、空格)的值(和潜在的键),您想要引用它们:
for i in "${!R[@]}"
do
printf "%-20s\n" "${R[i]}"
done