bash script read command issue with carriage return
Hello,
I am trying to catch carriage return input but with no success. works fine when $replay is Y,y,N or n but it doesn't catch carriage return. I've tried with ^K or ^L 'x0a' '\n' or '\r' and with $ like $'\n' or $'\r' but it doesn't work. here is the code: Code:
#! /bin/bash If someone has any idea I'll be glad. Regards, Itamar |
If you haven't done anything to change the terminal input mode, carriage return will be translated to newline. The read command will strip off the newline, so what you want to test for is your variable being null:
Code:
if [[ $replay =~ ^[YyNn]$ || $replay == "" ]] |
rknichols,
Thanks for the comment but I want to have 3 situations: 1. entering Yes or No. 2. Default - when the counter ends which will return null. 3. Pressing Enter to accept the default and continue. The problem is with this null value. Regarding the code you've suggested, if your not entering nothing the loop ends after 1 sec cause it thinks Enter has been pressed. Any other suggestion how can I achieve this method ? Regards, Itamar |
Test the return code from read. For a timeout, read will exit with a non-zero return code.
|
All times are GMT -5. The time now is 04:24 PM. |