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

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

Read command without enter

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

How to implement in shell script?

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


Post a Comment


dba topics. Copyright 2011-17 All Rights Reserved | Site Map | Contact | Disclaimer | Google