LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell read -p -s hanging, need to press enter key twice to make it run (https://www.linuxquestions.org/questions/linux-newbie-8/shell-read-p-s-hanging-need-to-press-enter-key-twice-to-make-it-run-4175451821/)

zousheng 02-26-2013 05:31 PM

shell read -p -s hanging, need to press enter key twice to make it run
 
Hi, when i try to input the password with read -s -p "": variable
then it's hanging, it needs me to press the enter key twice, don't know why, anyone can help? thanks

shivaa 02-26-2013 08:58 PM

Take a note that, option -s is used for supress or silent, and -p is for prompt, so use only -s.

If you want to hide the password, just do it like,
Code:

echo -n "Enter password: "
read -s passwd


unSpawn 02-26-2013 09:07 PM

Quote:

Originally Posted by shivaa (Post 4900524)
Take a note that, option -s is used for supress or silent, and -p is for prompt, so use only -s.

Using or leaving out '-p "";' doesn't have any effect on 'read' when using BASH 3.2.25(1) so this doesn't explain his observation of having to use enter twice.

grail 02-26-2013 11:38 PM

Seems to work just fine for GNU bash, version 4.2.39(1)-release

zousheng 02-27-2013 08:12 AM

Thanks for all your information, today i found the reason by accident. i put a if sentence and some other command after read, then after i input password, it didn't give reply at all, like it's still waiting me to input the password, but the fact is it's already running, then i add an echo "Program is running, please wait for a while...", then after I input the password, Program is running, please wait for a while... shows immediately, then i figured out this is the reason. thanks again.

grail 02-27-2013 09:29 AM

Please mark as SOLVED once you have a solution.


All times are GMT -5. The time now is 08:41 PM.