有没有办法在此Bash脚本中显示菜单前的提示?

时间:2016-02-04 22:29:40

标签: bash shell sh

有没有办法让以下Bash脚本显示两个提示中的每一个 之前选择菜单而不是之后?

感谢。

#!/usr/bin/env bash

PS3='Copy database to which server? '
options=("debug" "dev" "prod" "Quit")
select server in "${options[@]}"
do
    case $server in
        "debug")
            break
            ;;
        "dev")
            break
            ;;
        "prod")
            break
            ;;
        "Quit")
            echo "Quitting"
            exit 1
            ;;
        *) echo "Invalid option";;
    esac
done

PS3='Reuse existing user data or get fresh data? '
options=("existing" "fresh" "Quit")
select data in "${options[@]}"
do
    case $data in
        "existing")
            break
            ;;
        "fresh")
            break
            ;;
        "Quit")
            echo "Quitting"
            exit 1
            ;;
        *) echo "Invalid option";;
    esac
done

echo "You chose "$server" and "$data
exit 1

1 个答案:

答案 0 :(得分:0)

是......您可以随时使用echo

向用户撰写文字
echo 'Copy database to which server?'
options=("debug" "dev" "prod" "Quit")
select server in "${options[@]}"
do
    case $server in
        "debug")
            break
            ;;
        "dev")
            break
            ;;
        "prod")
            break
            ;;
        "Quit")
            echo "Quitting"
            exit 1
            ;;
        *) echo "Invalid option";;
    esac
done

这会给你:

Copy database to which server?
1) debug
2) dev
3) prod
4) Quit
#?