0

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:

enter image description here

alexandre
  • 141
  • 8

1 Answers1

0

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.

R4F6
  • 782
  • 1
  • 9
  • 26
  • 1
    It does not work very well with me, I can't see the "enter" when I press enter and I can't see the "space" when I press space, all I can see is Debug//0 – alexandre Nov 06 '17 at 17:18