Results 1 to 6 of 6
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
...
- 11-01-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
Unable to accept input during a script (bash "read")
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 resulting in a command not found error.
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 next prompt with a "command not found" error.
Any ideas? Its pretty hard to google for something like this since the word "read" is so common.
- 11-02-2007 #2
did you check first if your default Shell is bash , run this echo $SHELL , and also try to run your script sh script.sh
please let me know about your problem
Regards.Linux is not only an operating system, it's a philosophy.
Archost.
- 11-04-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
The following commands were run on the effected machine.
/var/tmp# echo $0
/bin/bash
/var/tmp# echo $SHELL
/bin/sh
I also created a file named script1.sh containing
echo "ABC"
read TEST2
echo $TEST2
echo TEST2
and ran it using sh script1.sh but it had the same problem.
- 11-04-2007 #4
This is very strange
open a terminal as a normal user and then type bash , and try to run your script , by the way wish distro you are using .
Regards.Linux is not only an operating system, it's a philosophy.
Archost.
- 11-05-2007 #5Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
The following shows the computer output in red and my input as black
/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 differentiate my input from the 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. The bash version is
/var/tmp# echo $BASH_VERSION
2.02.0(1)-release
- 11-06-2007 #6Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
I feel like an idiot. I found the problem. It was an issue with my telnet client

By default many telnet clients including Windows telnet.exe send both a carriage return and a line feed when you press enter. This was being picked up by the system as two separate events and causing the problem I described.
Thanks for the help. I hope someone can read this thread in the future and solve their own problem
edit: For windows Telnet.exe
unset crlf - return key only sends CR
and
set crlf - return key sends CR LF (normal operation)


Reply With Quote