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

_____________________________________________________________________________________________________________________

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 (580) General (60) Unix (47) Script (41) Blog (23) OCI (3) SQL* Loader (3) Datapump (2) Software (1)
DBA Tips
 

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