![]() |
How do I make my BASH script yes/no user input query terminate with 3 invalid inputs?
Hello all.
I have a BASH script which at one point asks the user a yes/no question. I want to make it so that if the user types in an invalid input 3 times consecutively then the BASH script will echo an error and terminate with exit status 1. Here is my current code:- Code:
...Thanks in advance. leopard |
Without doing it for you, a pseudo'd version:
Code:
err=0 |
Quote:
The script failed at " } else {" Here it is:- Code:
... |
Code:
(( err++ )) |
Yes, mine was pseudocode, not bash. It will error.
|
Quote:
I'm a newbie at BASH scripting... |
http://mywiki.wooledge.org/BashGuide
http://bash-hackers.org/wiki/doku.php Here are a couple of links that may help you. |
Pseudocode; break it into it's composite parts, pseudo and code. Code is simple, we know the definition of this. Pseudo means 'fake' or 'pretend' (Actually, it doesn't quite, but I'm not a linguist). Even better:
Code:
jc@jcmain:~$ dict pseudocodeWhat you need is to set a counter and increment it when an incorrect/invalid answer is given; then you can check this value and if it equals 3 you can return an 'Invalid Input' error |
Hi,
I like the Wikipedia definition; Quote:
|
Hi,
Just a few useful links; Linux Documentation Project Rute Tutorial & Exposition Linux Command Guide Bash Reference Manual Advanced Bash-Scripting Guide Linux Newbie Admin Guide LinuxSelfHelp Getting Started with Linux These links and others can be found at 'Slackware-Links' . More than just SlackwareŽ links! |
| All times are GMT -5. The time now is 01:51 PM. |