可以选择语句与tput一起使用

时间:2015-12-03 20:15:31

标签: bash

我想用select语句在屏幕中央创建一个菜单:

            tput cup $((height / 2)) $(((width / 2) - (length / 2)))
            echo ${warn_msg}
            tput cup $((height / 2 + 1)) $(((width / 2) - (length / 2)))
            select yn in "Accept" "Quit"
            do

问题是菜单的选择没有完全对齐:只有select语句的第一选择是居中的。

                  Disclaimer: This is a personal script. The author is not responsible for damage of any kind arising from its use.
                  1) Accept
2) Quit
Enter choice:

有没有人知道很好地调整选择的技巧?

2 个答案:

答案 0 :(得分:0)

(select yn in Accept Quit
do COMMANDS
done) |& sed -e "s/^/$(printf %$(( $(tput cols)/2-3 ))s ' ' )/"

答案 1 :(得分:0)

也许你喜欢这个($REPLY中返回的选项号码):

read < <(dialog 2>&1 >/dev/tty --nocancel --ok-label 'Enter choice' --menu \
'Disclaimer: This is a personal script.
The author is not responsible for damage of any kind arising from its use.' \
0 0 2  1 Accept  2 Quit)
echo You chose $REPLY.

或者这个($?中返回的选项):

dialog --yes-label Accept --no-label Quit --yesno \
'Disclaimer: This is a personal script.
The author is not responsible for damage of any kind arising from its use.' 0 0
echo You chose $(($?+1)).