LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-24-2011, 12:11 PM   #1
keimasi
Member
 
Registered: Dec 2010
Location: Iran, Tehran
Distribution: ubuntu
Posts: 31

Rep: Reputation: 0
Question 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
 
Old 02-24-2011, 12:28 PM   #2
someshpr
Member
 
Registered: Jul 2009
Location: CA, USA
Distribution: Debian, RHEL5.4, CentOS 5.4, 6.2, Ubuntu 11.04,12.04
Posts: 107

Rep: Reputation: 26
Quote:
Originally Posted by keimasi View Post
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?
 
Old 02-24-2011, 12:38 PM   #3
keimasi
Member
 
Registered: Dec 2010
Location: Iran, Tehran
Distribution: ubuntu
Posts: 31

Original Poster
Rep: Reputation: 0
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

Last edited by keimasi; 02-24-2011 at 12:40 PM. Reason: add something..........
 
Old 02-24-2011, 01:10 PM   #4
prowla
Member
 
Registered: Feb 2011
Location: UK
Distribution: RHEL 5 & 6, Ubuntu 10
Posts: 92

Rep: Reputation: 3
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
 
1 members found this post helpful.
Old 02-24-2011, 01:23 PM   #5
someshpr
Member
 
Registered: Jul 2009
Location: CA, USA
Distribution: Debian, RHEL5.4, CentOS 5.4, 6.2, Ubuntu 11.04,12.04
Posts: 107

Rep: Reputation: 26
Quote:
Originally Posted by keimasi View Post
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?
 
Old 02-24-2011, 01:38 PM   #6
keimasi
Member
 
Registered: Dec 2010
Location: Iran, Tehran
Distribution: ubuntu
Posts: 31

Original Poster
Rep: Reputation: 0
thanks alot I use
Code:
while [ -z ]
do
read ..
if
..
.
.
.
.
fi
done
and it works. it never stop till i pressed ^c.
 
Old 02-24-2011, 02:07 PM   #7
someshpr
Member
 
Registered: Jul 2009
Location: CA, USA
Distribution: Debian, RHEL5.4, CentOS 5.4, 6.2, Ubuntu 11.04,12.04
Posts: 107

Rep: Reputation: 26
If happy with solutions, please mark the thread as solved (located in the thread tools).
 
Old 02-25-2011, 04:42 AM   #8
keimasi
Member
 
Registered: Dec 2010
Location: Iran, Tehran
Distribution: ubuntu
Posts: 31

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by someshpr View Post
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....
 
  


Reply

Tags
bash, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script question: Shell script in kde to log in on a server with ssh c4719929 Programming 18 01-31-2011 09:26 AM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 03:05 AM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 08:40 AM
I want to run script on the server from client machine in windows in a perl script vpradeep Linux - Newbie 2 09-01-2008 03:29 AM


All times are GMT -5. The time now is 12:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration