PDA

View Full Version : Unable to accept input during a script (read command)



ciper
01-11-2007, 08:19 PM
I am having some trouble with my Tivo that I can't solve on my own. Ill try to keep this short -

I am having trouble with the read command. For some reason it is not accepting any input.

For example if I run it directly from the bash prompt as follows
read test
and type
123
Then run the set command I can see that an environment variable named test has been created but it is blank.

Once the read command has exited the string I typed (123 in this example) is then output to the bash prompt.

The same thing happens in a script. For example
echo "enter password"
read password
echo $password


Will echo nothing and then whatever I typed during the script will then be entered at the bash prompt usually with a "command not found" error
In other words I cant create a script that takes input from the user!

Any help?

MattCallow
03-11-2007, 11:11 AM
That's strange. Have you tried putting read in single quotes (which will ensure that the real command is used, not an alias)
Also using test as a variable name is probably not a good idea as it's a bash builtin command
try

'read' ans
echo $ans

ciper
04-11-2007, 03:41 PM
Thanks for the ideas. I created a file named script1.sh containing
echo ANS
'read' ANS
echo $ANS
echo ANS
and ran it using sh script1.sh but it had the same problem.

MattCallow
04-11-2007, 08:20 PM
Can you try the following commands, and paste the results here (response from Tivo in red your input in black):



[TiVo [p1] ~]# exec /bin/bash
bash-2.02# 'read' ans
123
bash-2.02# echo $ans
123
bash-2.02#


Are you connected to the tivo using telnet or serial port?

ciper
06-11-2007, 10:05 AM
Connected to the Tivo over the internet

/var/tmp# exec /bin/bash
/var/tmp#
/var/tmp# 'read' ans
123

/var/tmp# 123
bash: 123: command not found
/var/tmp#
/var/tmp# echo $ans

/var/tmp#

I was VERY careful to accurately represent my input from the Tivo's ouput using color. Notice the line above "command not found"
Here is the truncated output of "set"
...
_=echo
ans=
prom=r
...

Notice that "ans" is getting set by read but the input is getting dumped back to the next bash prompt.

MattCallow
06-11-2007, 10:14 AM
Ah - I think I know what the problem is. Your telnet client is sending 2 newlines when you hit enter (or at least that's how the TiVo is interpreting it).
you can see this because you get an extra prompt after each command. Are you using putty as your telnet client by any chance? You need to change a setting in your telnet client. For putty, under Connection/telnet untick the box which says 'Return key sends Telnet new Line instead of ^M'

Matt

ciper
06-11-2007, 11:55 AM
LOL!! MattCallow wins the internet for today. I posted this question all over the place including many Linux forums and IRC channels where people either didnt answer or said stuff like "your bash is really broken" ...

I tried using hyperterminal and it worked. Originally I was using telnet.exe so I will try to out how to adjust its settings.

Thanks :) I owe you one.

edit: For windows Telnet.exe
unset crlf
Line feed mode - Causes return key to send CR
and
set crlf
New line mode - Causes return key to send CR & LF

MattCallow
06-11-2007, 12:39 PM
Glad to be of help. It's a difficult one to diagnose unless you see the exact input and output. I only know about it because I had experienced the problem with putty.

Matt