03-18-2006
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.
10 More Discussions You Might Find Interesting
1. SuSE
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
2. UNIX for Dummies Questions & Answers
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. UNIX for Dummies Questions & Answers
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
6. Shell Programming and Scripting
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
7. Programming
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
8. Shell Programming and Scripting
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
9. UNIX for Dummies Questions & Answers
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
10. Shell Programming and Scripting
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
LEARN ABOUT REDHAT
escape
escape(1) Mail Avenger 0.8.3 escape(1)
NAME
escape - escape shell special characters in a string
SYNOPSIS
escape string
DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result.
EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string:
$ var='; echo gotcha!'
$ eval echo hi $var
hi
gotcha!
$
Using escape, one can avoid executing the contents of $var:
$ eval echo hi `escape "$var"`
hi ; echo gotcha!
$
A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For
example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient:
#!/bin/sh
formail -x to -x cc -x resent-to -x resent-cc
| fgrep "$1" > /dev/null
&& exit 0
echo "<$1>.. address does not accept blind carbon copies"
exit 100
To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt
script:
bodytest reject_bcc `escape "$RECIPIENT"`
SEE ALSO
avenger(1),
The Mail Avenger home page: <http://www.mailavenger.org/>.
BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells.
AUTHOR
David Mazieres
Mail Avenger 0.8.3 2012-04-05 escape(1)