我想做的是将菜单项存储在数组中并动态检索它们,以获得尽可能多的可重用性。如以下代码所示,我在 ***
行遇到语法错误。该代码源自 Dialog
包示例。
function showSubMenu() {
. ./setup-vars
. ./setup-tempfile
$DIALOG --clear --title $1 $2 \
--menu "" $3 \
*** (for line in $4
do
$line ""
done) 2> $tempfile
retval=$?
. ./report-tempfile
}
TITLE="MyStrings"
TT= "$@"
MSG=("Linux" "Gentoo" "Arch" "Buildroot" "Ubuntu" "Debian" "RedHat")
SIZE="20 30 6"
for i in ${MSG[@]}
do
echo $i
done
showSubMenu $TITLE $TT $SIZE ${MSG[@]}
我的问题是: 1.这样的代码可以吗? 2. 如果没有,是否还有其他可能或类似的想法可以做到这一点?
最佳答案
我明白了。
function showSubMenu() {
. ./setup-vars
. ./setup-tempfile
$DIALOG --clear --title $1 $2 \
--menu "" $3 \
`(for line in $4
do
printf "${line}"
done)` 2> $tempfile
retval=$?
. ./report-tempfile
}
TITLE="MyStrings"
TT= "$@"
MSG=("Linux" "Gentoo" "Arch" "Buildroot" "Ubuntu" "Debian" "RedHat")
SIZE="20 30 6"
for i in "${MSG[@]}"
do
echo $i
done
showSubMenu $TITLE $TT $SIZE MSG[@]
关于Linux Dialog 包参数插入 for/while 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42095972/