echoed prompt not appearing until after read command.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echoed prompt not appearing until after read command.
# 1  
Old 03-18-2006
Question echoed prompt not appearing until after read command.

I have a script I am runing on a hacked CDLinux live CD called from /etc/rc.d/rc.local.

The part of th script in question goes like this.
Quote:

colour() {
case "$1" in
"shout" ) echo -ne "\033[1m\033[41m";;
"welcome" ) echo -ne "\033[1;33m\033[40m";;
"error" ) echo -ne "\033[1;31m\033[40m";;
"info" ) echo -ne "\033[1;36m\033[40m";;
"normal" ) echo -ne "\033[0m";;
* ) echo -ne "\033[0m";;
esac
}

while [ 0 ]; do
colour info
echo -n "Place name :"
read place_name
funnychars=`echo $place_name | tr -d '[a-z][A-Z][0-9] '`
if [ -z "$funnychars" ]; then break; fi
colour normal
echo
echo
colour error
echo "Letters, spaces and numbers only, please. Remove any $funnychars"
echo -n "from name. Try again."
colour normal
echo
done
colour normal
echo
When run from rc.local the prompt "Centre name :" and the colour change does not appear until after I type the input text and press return. Also, I noticed CTRL-C does not interrupt this script even when it pauses for keyboard input.

When I run the same script after logging from the console it all works as expected with the prompt appearing before the keyboard input.

Sorry if the colour change code isn't relavent here but I have a long debug loop that involves re-burning the CD to test this script in failure mode, so it's probably quicker to post the whole thing just in case.
# 2  
Old 03-18-2006
In a start up script, you are seldom simply talking to a tty device. Instead, you are talking to logging program or psuedo device. It captures the messages and sends them to syslog. Eventually someone along the way sends them to the console as well. It is probably line buffered from your description. You could just line with it. Always send a newline character with every echo. This means your prompt won't be on the same line as the user input. Or you could try to explicitly open the console....
exec > /dev/console 2>&1

assuming your console is called /dev/console.
# 3  
Old 03-19-2006
Yes, that fixed it!

I did a slight variation based on what I found in a Slackware rc.local script.

Quote:
exec </dev/console >/dev/console 2>&1
Not sure if it makes much difference (I have to burn another CD to find out), but I'm happy the script is behaving itself now.

Thanks for helping :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

OSX read silent with prompt

A minor nitpick, but I cannot get a statement like: read -s -n 1 -p "Say Y or N here" -e ANS to actually hush the response. If I don't use the -p option, the response is silent. With it, I always see the response, and I've tried putting the -s in different spots. Is this a known issue, or... (2 Replies)
Discussion started by: jnojr
2 Replies

2. UNIX for Dummies Questions & Answers

PS1 (Prompt character) appearing in cat output

RedHat Linux 5.8/Korn Shell I have text file name /etc/oracle/config.loc. It has the following text #Device/file getting replaced by device +OCR ocrconfig_loc=+DATA ocrmirrorconfig_loc=+OCRBut , when I open this file using cat , the PS1 character (for prompt) appears as the last character... (8 Replies)
Discussion started by: omega3
8 Replies

3. Shell Programming and Scripting

Using read to prompt for editable user input in Bash 3

Below is a simple script to prompt for user input while suggesting an editable default value at the prompt: shortname=user1 read -e -i $shortname -p "Please enter the username you would like to add: " input USERNAME="${input:-$shortname}" Please enter the username you would like to add:... (3 Replies)
Discussion started by: woodson2
3 Replies

4. Programming

PHP Echoed in Ajax

I have built a site in PHP for radio station, and the daily schedule is displayed dynamically using PHP script. I have added links to view different days but when it loads up its just loading up a new page. I can't quite remember how I done it but I'd like it to be in ajax if that's... (2 Replies)
Discussion started by: AimyThomas
2 Replies

5. Shell Programming and Scripting

space after read prompt?

Hello, Unix-Forums. How can I make a Space after a read prompt? let's assume: read -p "Are you good?:" varthe output would be ( | is the cursor ): Are you good?:|But I want it to be: Are you good?: |That's what I mean. How would I do that? (2 Replies)
Discussion started by: intelinside
2 Replies

6. UNIX for Dummies Questions & Answers

pine email tool suppress prompt to save read messages

Could somebody please advise about how to configure pine/alpine so that on exit it doesn't prompt me to save read messages? Thanks (3 Replies)
Discussion started by: LeoKSimon
3 Replies

7. Shell Programming and Scripting

execution of a string being echoed in bash

hi all, I am trying to do a loop on a series of plotting function shown below: colorlist=(blue red green); n=0; for k in $xy; do psbasemap $range -JM$scale -B10g5 -X1 -Y1 -P -K > $outfile pscoast $range -JM$scale -B10g5 -D$res -P -W$lwidth -G$fill -O -K >> $outfile echo... (1 Reply)
Discussion started by: ida1215
1 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. UNIX for Dummies Questions & Answers

Putting echoed text into a new file

Hi, I've set up a script so that a user answers questions, and then these answers come back onto the screen accompanied by text that I've echoed. Is there a way of putting this into a new file? Thanks (7 Replies)
Discussion started by: likelylad
7 Replies

10. SuSE

inconsistent ls command display at the command prompt & running as a cron job

Sir, I using the following commands in a file (part of a bigger script): #!/bin/bash cd /opt/oracle/bin ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out If I run this from the command prompt the result is: 2007-05-16 if I run it as a cron job then... (5 Replies)
Discussion started by: rajranibl
5 Replies
Login or Register to Ask a Question