bash scripting - read single keystroke including special keys enter and space

后端 未结 3 1982
轻奢々
轻奢々 2020-12-31 18:54

Not sure if I should put this on stackoverflow or unix.stackexchange but I found some similar questions here, so here it goes.

I\'m trying to create a script to be c

3条回答
  •  梦谈多话
    2020-12-31 19:36

    #!/bin/bash
    SELECT=""
    # prevent parsing of the input line
    IFS=''
    while [[ "$SELECT" != $'\x0a' && "$SELECT" != $'\x20' ]]; do
      echo "Select session type:"
      echo "Press  to do foo"
      echo "Press  to do bar"
      read -s -N 1 SELECT
      echo "Debug/$SELECT/${#SELECT}"
      [[ "$SELECT" == $'\x0a' ]] && echo "enter" # do foo
      [[ "$SELECT" == $'\x20' ]] && echo "space" # do bar
    done
    

提交回复
热议问题