prompt - Bash confirm input or re enter -
i have simple bash script asks user if enter input. response y
or n
if enter n
script exits.
if enter y
asked questions. @ end want ask them confirm input.
if it's correct we'll carry on, if not want return them questions re enter information.
so far i've got:
while true; echo -e "enter details ? " read yn case $yn in [nn]* ) exit;; [yy]* ) echo -e "description" read desc echo -e "address" read address * ) echo "please answer yes or no.";; esac done
this seems work fine, i've tried add confirmation.. thats not working.
while true; echo -e "enter details ? " read yn case $yn in [nn]* ) exit;; [yy]* ) echo -e "description" read desc echo -e "address" read address echo -e "$desc - $address" while true; echo -e "\nare these details correct ? " read conf case $conf in [nn]* ) // return enter details // [yy]* ) // carry on details entered // break;; esac done * ) echo "please answer yes or no.";; esac done
the aim follows
the user selects y
, enters description , address. page shows them summary of they've entered , asks them are these details correct ?
if move on , script progresses. the input wrong script returns them enter description followed enter address.
can advise how this. thanks
you add 1 more loop level , use optional level indicator of break [n]
:
while true; echo -e "enter details ? " read yn case $yn in [nn]*) exit;; [yy]*) while true; echo -e "description" read desc echo -e "address" read address echo -e "$desc - $address" while true; echo -e "\nare these details correct ? " read conf case $conf in [nn]* ) break 1;; [yy]* ) break 3;; esac done done;; *) echo "please answer yes or no.";; esac done
Comments
Post a Comment