STEP# | CODE | COMMENT |
---|---|---|
01 | echo -n "Are you sure (Y/N)? " |
print prompt just once with echo |
02 | answered= |
initiate an empty test binding |
03 | while [[ ! $answered ]]; do |
loop until test binding is populated |
04 | read -r -n 1 -s answer |
get input, supress escape, only 1 char, supress input |
05 | if [[ $answer = [Yy] ]]; then |
test if input is y or Y |
06 | answered="yes" |
..if true, set test binding to yes → step #12 |
07 | elif [[ $answer = [Nn] ]]; then |
else, test is input is n or N |
08 | answered="no" |
..if trye, set test binding to no → step #12 |
09 | fi |
end of the test |
10 | done |
end of the loop |
12 | printf "\n%s\n" $answered |
print formatted result enclosed with two newlines |
Created
January 13, 2022 08:15
-
-
Save pkutaj/58748eda4242e3a79ff3b951149da143 to your computer and use it in GitHub Desktop.
Ask for Input in Bash Rubberduck Table
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment