LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   help for my script... (http://www.linuxquestions.org/questions/programming-9/help-for-my-script-864803/)

keimasi 02-24-2011 01:11 PM

help for my script...
 
Hi 2 all friends...
I just write a script that check some thing. and I use
Code:

read -p " enter : " chk
it executed. but if a user use "Enter key" on keyboard it cant continue and finish.

I hope I explain well ...

if u can please guide me..
thanks

someshpr 02-24-2011 01:28 PM

Quote:

Originally Posted by keimasi (Post 4269894)
Hi 2 all friends...
I just write a script that check some thing. and I use
Code:

read -p " enter : " chk
it executed. but if a user use "Enter key" on keyboard it cant continue and finish.

I hope I explain well ...

if u can please guide me..
thanks

Do you mean that the script you wrote supposed to do something after read, but it stops after executing the read command?

The command "read" reads a line from standard input till the user hits the "Enter key". So read command is supposed to exit after the one presses "Enter".

Sorry, but I do not clearly understand what is your problem. Can you explain a little more what your script is supposed to do?

keimasi 02-24-2011 01:38 PM

It execute completely and and do whatever should to do. But I mean i want to disable " Enter key" on keyboard during that script is executing and users wont be able to stop my script by pressing Enter key.

you know if user press "Enter" it can not continue and will stop

prowla 02-24-2011 02:10 PM

I'm not sure I exactly understand, but would this keep prompting if just Enter was pressed?:

Code:

chk=''
while [ -z "$chk" ]
do
  read -p " enter : " chk
done


someshpr 02-24-2011 02:23 PM

Quote:

Originally Posted by keimasi (Post 4269918)
It execute completely and and do whatever should to do. But I mean i want to disable " Enter key" on keyboard during that script is executing and users wont be able to stop my script by pressing Enter key.

you know if user press "Enter" it can not continue and will stop

Sorry, I am still confused!
Pressing "Enter" as a response to the "read" command in your script should not stop the script. Is it stopping the script? How is user able to stop the script by pressing "Enter key"?
I believe, "read" needs a "Enter" to understand the stdin has ended. So I am not sure "disabling Eneter key" will be possible at all if you are reading from stdin.

If you want to prevent user entering blank line as a response to the read command, you can follow what prowla suggested.

If this is not the case, can you please post the relevant parts of the script (replacing sensitive information, of course), the intended output, and the output when the user presses enter after the read statement and the script stops?

keimasi 02-24-2011 02:38 PM

thanks alot I use
Code:

while [ -z ]
do
read ..
if
..
.
.
.
.
fi
done

and it works. it never stop till i pressed ^c.

someshpr 02-24-2011 03:07 PM

If happy with solutions, please mark the thread as solved (located in the thread tools).

keimasi 02-25-2011 05:42 AM

Quote:

Originally Posted by someshpr (Post 4270024)
If happy with solutions, please mark the thread as solved (located in the thread tools).


Thanks for your advice..
But I did it before you said that....
:)


All times are GMT -5. The time now is 10:19 AM.