I would like to create a shell script that asks the user to select radio buttons using the space bar. I have searched a lot but wasn't able to find anything.
Here is an example of what I am talking about:
I would like to create a shell script that asks the user to select radio buttons using the space bar. I have searched a lot but wasn't able to find anything.
Here is an example of what I am talking about:
See this thread for how to record the key stroke: bash scripting - read single keystroke including special keys enter and space
However, you will need to also use need to echo the options provided to the same lines, instead of writing new lines: How to show and update echo on same line
So in this case, your script would look something like:
#!/bin/bash
SELECT=""
while [[ "$SELECT" != $'\x0a' && "$SELECT" != $'\x20' ]]; do
echo "Press <Space> to move selection"
echo "Press <Enter> to confirm selection"
read -d'' -s -n1
echo "Debug/$SELECT/${#SELECT}"
[[ "$SELECT" == $'\x0a' ]] && echo "enter" # do your install stuff
[[ "$SELECT" == $'\x20' ]] && echo "space" && echo -ne "$options" # reprint options
done
Edit: Actually printf
probably would be better in this case.