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

Is there a way to display prompt before menu in this Bash script?

有没有办法让下面的Bash脚本分别显示两个提示 它的select菜单之前而不是在它之后?

谢谢。

#!/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

是的...您可以随时通过 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
#?