How to read (command) without enter in Linux bash shell?

advertisements

_____________________________________________________________________________________________________________________

The Eucharistic Miracles of the World
By default the read command wait for a Enter Key to complete the command. But if  you –n 1 option it will not wait for the enter key. Once it counts one(n=1) key press in the standard input it will come out and assign the value to the variable.

Normal read command with enter


read -p "Are you Sure?" ans
Are you Sure?y
$ echo $ans
Y

Read command without enter

read -p " Are you Sure?" -n 1 ans
Are you Sure?y$
$ echo $ans
y

How to implement in shell script?

proceed=$(bash -c 'read -p " Are you Sure ? " -n 1 ans;echo "$ans"')

_____________________________________________________________________________________________________________________

Website Stats

0 comments:

Post a Comment

Labels

Oracle (629) Script (86) General (77) Unix (47) Blog (23) Technology (19) gadget (6) games (6) Business (3) OCI (3) SQL* Loader (3) Datapump (2)
 

acehints.com Copyright 2011-23 All Rights Reserved | Site Map | Contact | Disclaimer