Create interactive shell script. Prompt for Yes / No input | Drupal 8

Create interactive shell script. Prompt for Yes / No input

Submitted by editor on Thu, 02/09/2017 - 15:55
Question

How do I prompt for Yes/No/Cancel input in a Linux shell / bash script ?
Ask question / input value.

Prompt for Yes/No/Cancel input in a Linux shell / bash script

Example:

#!/bin/bash

echo "This script will ask a question.";

while true; do
    read -p "Do you want to continue ?" yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

echo "Your answer is 'YES'";

Tags

Add new comment