The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ls while read loop - internal read picking up wrong input dkieran Shell Programming and Scripting 2 05-14-2007 03:02 PM
about READ...please help! fiol73 UNIX for Dummies Questions & Answers 1 12-28-2006 09:23 PM
Cannot read in variable using read on first try normie UNIX for Advanced & Expert Users 1 10-05-2005 01:42 AM
read line and read next ariuscy UNIX for Dummies Questions & Answers 7 09-21-2005 07:04 AM
drw-r--rw- Not able to read rs_reddy HP-UX 3 11-16-2003 06:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-05-2008
davegerdt davegerdt is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
read is not pausing to read

Can anyone tell me why this section of my script doesn't work? The script is designed to accept piped data, store it in a temporary location, and then prompt the user for their user name. It doesn't stop to read the username, however. It just finishes.

It is called like:
Code:
cat datafile | myscript
The script is as follows:
Code:
datafile1="data$$.dat"
datafile2="data$$2.dat"
pdffile="pdf$$.pdf"

# Store piped data
cat > $datafile1

# Prompt for username
echo "Enter your username:"

# Read username
read username
I also tried adding a loop trying to clear out the input data that I assumed was being left around, as shown in the following, but it didn't change anything.

Code:
# Store piped data
cat > $datafile1

while [ -z username ]
do
    read username
done

# Prompt for username
echo "Enter your username:"

# Read username
read username
What am I missing? Thanks for the help!
  #2 (permalink)  
Old 04-05-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
echo "enter your user name:" > /dev/tty
read username < /dev/tty
  #3 (permalink)  
Old 04-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Just to expand on the answer a little bit, when you pipe something to a command, the shell changes the input file descriptor so the command is no longer reading from the terminal, but from the pipeline. There is no way you can get interactive user input from the default file descriptor, so you need to read it from somewhere else. /dev/tty is usually a good choice for reading from the terminal.
  #4 (permalink)  
Old 04-07-2008
davegerdt davegerdt is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
Thanks for the solution and explanation. Makes perfect sense.
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 On




All times are GMT -4. The time now is 09:40 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0