BASH Download de arquivos

0

Agora tudo que eu tenho problemas com o sim não é declarações. Eles não estão permitindo a entrada, mas sim a configuração como o resto deles ...

mc_addplugin() {
    if pgrep -u $USERNAME -f $SERVICE > /dev/null
    then
        echo "$SERVICE is running!"
        echo "Please stop the service before adding a plugin."
    else
        echo "Paste the URL to the .JAR Plugin..."
        read JARURL
        JARNAME=$(basename "$JARURL")
        echo "$JARNAME"
        if [ -d "$TEMPPLUGINS" ]
        then
            as_user "cd $TEMPLUGINS && wget -A.jar -O ./$JARNAME $JARURL"
        else
            as_user "cd $PLUGINSPATH && mkdir $TEMPPLUGINS && cd $TEMPPLUGINS && wget -A.jar -O ./$JARNAME $JARURL"
        fi
        if [ -f "./$JARNAME" ]
        then
            as_user "cd $PLUGINSPATH"
            if [ -f "./$JARNAME" ]
            then
                if 'diff $PLUGINSPATH/$JARNAME $TEMPPLUGINS/$JARNAME >/dev/null'
                then 
                    echo "You are already running the latest version of $JARNAME."
                    NOW='date "+%Y-%m-%d_%Hh%M"'
                    echo "Are you sure you want to overwrite this plugin? [Y/n]"
                    echo "Note: Your old plugin will be moved to the "$TEMPPLUGINS" folder with todays date."
                    select yn in "Yes" "No"; do
                        case $yn in
                            Yes ) as_user "mv $PLUGINSPATH/$JARNAME $TEMPPLUGINS/${JARNAME}_${NOW} && mv $TEMPPLUGINS/$JARNAME $PLUGINSPATH/$JARNAME && rm -rf $TEMPPLUGINS";
                                    echo "Plugin has been install successfully!"; break;;
                            No ) echo "The plugin has not been installed! Removing temporary plugin and exiting..."
                                as_user "rm $TEMPPLUGINS/$JARNAME"; exit;;
                        esac
                    done
                    echo "Would you like to start the $SERVICE now? [Y/n]"
                    select yn in "Yes" "No"; do
                        case $yn in
                            Yes ) mc_start; break;;
                            No ) "$SERVICE not running! To start the service run: /etc/init.d/craftbukkit start"; exit;;
                            esac
                    done
                else
                    NOW='date "+%Y-%m-%d_%Hh%M"'
                    echo "Are you sure you want to overwrite this plugin? [Y/n]"
                    echo "Note: Your old plugin will be moved to the "$TEMPPLUGINS" folder with todays date."
                    select yn in "Yes" "No"; do
                        case $yn in
                            Yes ) as_user "mv $PLUGINSPATH/$JARNAME $TEMPPLUGINS/${JARNAME}_${NOW} && mv $TEMPPLUGINS/$JARNAME $PLUGINSPATH/$JARNAME && rm -rf $TEMPPLUGINS";
                                    echo "Plugin has been install successfully!"; break;;
                            No ) echo "The plugin has not been installed! Removing temporary plugin and exiting..."
                                as_user "rm $TEMPPLUGINS/$JARNAME"; exit;;
                        esac
                    done
                    echo "Would you like to start the $SERVICE now? [Y/n]"
                    select yn in "Yes" "No"; do
                        case $yn in
                            Yes ) mc_start; break;;
                            No ) "$SERVICE not running! To start the service run: /etc/init.d/craftbukkit start"; exit;;
                            esac
                    done
                fi
            else
                echo "Are you sure you want to add this new plugin? [Y/n]"
                select yn in "Yes" "No"; do
                    case $yn in
                        Yes ) as_user "mv $PLUGINSPATH/$JARNAME $TEMPPLUGINS/${JARNAME}_${NOW} && mv $TEMPPLUGINS/$JARNAME $PLUGINSPATH/$JARNAME"; break;;
                        No ) echo "The plugin has not been installed! Removing temporary plugin and exiting..."
                            as_user "rm $TEMPPLUGINS/$JARNAME"; exit;;
                    esac
                done
                echo "Would you like to start the $SERVICE now? [Y/n]?"
                select yn in "Yes" "No"; do
                    case $yn in
                        Yes ) mc_start; break;;
                        No ) "$SERVICE not running! To start the service run: /etc/init.d/craftbukkit start"; exit;;
                    esac
                done
            fi
        else
            echo "Failed to download the plugin from the URL you specified!"
            exit;
        fi
    fi
}

Quando você corre, você recebe algo como:

You are already running the latest version of Vault.jar.
Are you sure you want to overwrite this plugin? [Y/n]
Note: Your old plugin will be moved to the /home/pyrexiacraft/server/plugins/temp_plugins folder with todays date.
1) Yes
2) No
#? y
    
por WASasquatch 11.07.2012 / 20:34

1 resposta

1

select espera que você insira o número correspondente; 1 para Sim ou 2 para Não neste caso.

Ainda assim, a string real que o usuário digitou fica armazenada na variável chamada REPLY , assim você pode analisar isso além dos números.

Eu acabei de escrever uma função para perguntas sim / não; uma consulta sim / não não é para o que select foi projetado. Algo como

confirm() {
    local answer
    read -p "$1" -n1 answer
    while [[ $answer && $answer != [YyNn] ]]; do
        printf '\nPlease answer y or n\n' >&2
        read -p "$1" -n1 answer
    done
    printf '\n'
    [[ -z $answer || $answer = [Yy] ]]
}

#...

if confirm "Are you sure? [Y/n] "; then
    printf 'Ok\n'
else
    printf 'Fine, I will find something else to do\n'
fi

Y, y ou ENTER farão a função retornar true, N ou n farão a função retornar false. Você pode estendê-lo para obter o valor padrão como segundo argumento.

    
por geirha 12.07.2012 / 00:48