#! /bin/bash
# Usage: yesno prompt...
# Copyright (c) 2019, AT&T Intellectual Property. All rights reserved.
#
# Copyright (c) 2014 by Brocade Communications Systems, Inc.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-only


default=
if [ "$1" = "-y" ]
then default='y'; shift
elif [[ "$1" = "-n" ]]; then
  default='n'; shift
fi


if [ $# -eq 0 ]
then prompt="yes or no: "
else prompt="$*"
fi

while true
do
    read -p "$prompt" || exit 1
    if [ -z "$REPLY" -a ! -z "$default" ]
    then REPLY=$default
    fi
    case "$REPLY" in
    y*|Y*)	exit 0;;
    n*|n*)	exit 1;;
    *)		echo "Answer yes or no please";;
    esac
done


    
