Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2006
Registered User
 

Join Date: Apr 2006
Posts: 26
Strange behavior from 'read' statements. (ksh - but could be same on other shells)

I'm getting rather frustrated with an interactive script I'm writing.

The script is divided up, with section for setting variable at the top, then functions (which make up most of the script) then basically a line at the end which calls the first function- the program moves between the functions to do it's thing.

The problem I'm having is when I'm using 'read' to ask the user to 'press return to continue' or suchlike, at some points in the script this works FINE, however at other points it just continues straight through the 'read' without waiting for input or anything. Using 'read -u' had no effect, I have also replaced all these prompts with the following function;

pressreturn() {
echo
echo "Press <RETURN> to continue."
read BLANK
}

This has had no positive effect, the script still ignores the read statement some of the time!

I'm using ksh version M-11/16/88f on AIX 5.2

Thanks for your time on this, folks. I know I havn't provided too much information, I was just hoping this was a not-uncommon gotcha that a few of you might have come up against at one point or another. If anyone requires further information please shout and I'll supply whatever you need.

Regards,

Alex
Sponsored Links
  #2 (permalink)  
Old 04-04-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,148
echo > /dev/tty
echo "Press <RETURN> to continue." > /dev/tty
read BLANK < /dev/tty
  #3 (permalink)  
Old 04-28-2006
Registered User
 

Join Date: Apr 2006
Posts: 26
Many thanks, Perderabo, that worked a treat. Can you explain, or preferably point me to a website/free resource where I can read up on why your solution works. I have a few guesses but this whole thing has highlighted large gaps in my knowledge of UNIXland...

Again, many thanks!
  #4 (permalink)  
Old 05-01-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,148
Sometimes you are running with input redirected from a file. So "read BLANK" just reads one line from that file.
  #5 (permalink)  
Old 05-02-2006
Registered User
 

Join Date: Apr 2006
Posts: 26
Does this happen without me explicitly requesting it. I know that from the shell you can do this by calling <program> thus '<program> < inputfile', is this what you mean? If so, then how is this happening when I'm not requesting it? Thanks and regards - Alex.
  #6 (permalink)  
Old 05-02-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,148
The shell only does what you tell it to. I have no way to guess the specifics of what you did.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
strange behavior of find with xargs jerardfjay Shell Programming and Scripting 9 08-09-2007 09:06 AM
Very Strange Behavior for redirection cahook Shell Programming and Scripting 5 08-08-2007 12:32 PM
Strange Real Memory usage behavior Skyybugg AIX 5 05-31-2007 11:17 AM
Strange Behavior on COM2 Elwood51 UNIX for Dummies Questions & Answers 0 08-02-2006 04:31 PM
strange sed behavior Kevin Pryke UNIX for Dummies Questions & Answers 5 06-13-2003 05:34 AM



All times are GMT -4. The time now is 05:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0