Tohiko
Tohiko

Reputation: 1982

Read input and exit on "^G"

I am using the command

read -n 1 -p "$prompt" reply </dev/tty

to read one character from the user and execute the correct action. I would like to exit my program if the use pressed Ctrl+G instead of the allow inputs. However, I don't know how to do the comparison between $reply and ^G.

Any idea how?

Upvotes: 2

Views: 70

Answers (1)

Cyrus
Cyrus

Reputation: 88776

[[ $reply = $'\x07' ]] && exit

To find it:

read -n 1 reply; echo -n "$reply" | hexdump -C

Upvotes: 2

Related Questions