the shell not pause when execute read command

Hi, i facing a problem when run the script below..

while [ -z "$ea_ident" -o -n "`grep 2>/dev/null \"^EA $ea_ident$\" $EA_run_file`" ]
do

if [ $all_OMC -ne 1 ]
then
printf "Please enter a name : [${omc_ident}] "
read response # the problem occur here

if [ -z "$response" ]
then
  ea\_ident=$\{omc_ident\}
else
  \#
  \# Check that name does not contain invalid characters
  \#
  ea_ident=\`echo $response | tr -d "/ \\011"\`

  if [ -z "$\{ea_ident\}" -o "$\{ea_ident\}" != "$\{response\}" ]
  then
    echo
    echo "Sorry, not a valid name!"
    echo "Must not contain spaces, tabs or '/'."
    echo
    ea_ident=
  fi
fi
else  
  ea\_ident=$\{omc_ident\}
fi

   
if [ -n "\`grep 2>/dev/null \\"EA $ea_ident$\\" $EA\_run_file\`" ]
then
  echo "That name is already in use."
fi

done

$ea_ident is a data , when get into the loop, when excute read command, shell suppose to pause and wait for user input...

But in my case, its not and straight away execute the
next statement -> if [ -z "$response" ] ,

i did try to use </dev/tty but yet still no use..

Please post me any solution for this... Thanks

Maybe silly question :
Why "printf "Please ..."
All your other lines, you used echo...

I just simply put it..
but i dont think it will cause this problem...

How can you be sure you entered in the loop?

Im pretty sure if I put:

printf "Please enter a name : [${omc_ident}] "
read response # the problem occur here

in a script, it would display and prompt for answer

actually in my scritps, i did follow the flow by put echo messages
and it was entered the loop
and execute both printf and read command, but it didnt pause for user input..

do u have any idea,how to solve this problem :confused:... Thanks

ant:/home/vbe/scripts $ all_OMC=2
ant:/home/vbe/scripts $ if [ $all_OMC -ne 1 ]^Jthen^Jprintf "Please enter a name : [>
Please enter a name : []

It does works...
So I believe it before and you dont enter the condition...
Why not try with sh -x ?

Your code seems to work fine for me as well, both on Linux and HP-UX.

How are you actually running this script? In what shell and on what OS?

Im running in Putty, my local machine is window but the server is unix..

Using the shell : #!/bin/sh

vbe,

That is to avoid the automatic line feed you get at the end of an echo. In other words he wants to read the user input on the same line as the prompt.

neruppu,

Did you try vbe's sh -x suggestion? What exactly happens, does it loop endlessly like this?

$ ./neruppu
Please enter a name : []
Please enter a name : []
Please enter a name : []
Please enter a name : []
Please enter a name : []
Please enter a name : []
Please enter a name : []
...

Nope but i try this solution,
exec 3<&0
while
...............
...............
read response <&3
...............
...............
done <$input

and i get the endlessly like u mention above...

Ah! You never mentioned this <$input before! Are you trying to make things more challenging for us or something?? What is contained in $input anyway?

Try read -u3 response instead of read response <&3 if your OS supports it. You still haven't said which OS by the way...

I reformated your script so that I could actually read it. I defined a couple of variables so I could get it to run. The result....

$ cat mess
#! /usr/bin/ksh

all_OMC=0
EA_run_file=data
while [ -z "$ea_ident" -o -n "`grep 2>/dev/null \"^EA $ea_ident$\" $EA_run_file`" ] ; do

        if [ $all_OMC -ne 1 ] ; then
                printf "Please enter a name : [${omc_ident}] "
                read response # the problem occur here

                if [ -z "$response" ] ; then
                        ea_ident=${omc_ident}
                else
                        #
                        # Check that name does not contain invalid characters
                        #
                        ea_ident=`echo $response | tr -d "/ \011"`

                        if [ -z "${ea_ident}" -o "${ea_ident}" != "${response}" ] ; then
                                echo
                                echo "Sorry, not a valid name!"
                                echo "Must not contain spaces, tabs or '/'."
                                echo
                                ea_ident=
                        fi
                fi
        else
                ea_ident=${omc_ident}
        fi


        if [ -n "`grep 2>/dev/null \"EA $ea_ident$\" $EA_run_file`" ] ;  then
                echo "That name is already in use."
        fi

done
$ ./mess
Please enter a name : [] it is pausing for me!

Sorry, not a valid name!
Must not contain spaces, tabs or '/'.

Please enter a name : [] kjhkjhkjhkjh
$

You have posted an excerpt from a script and you assume that the error is in the excerpt that you gave us. This is not true. Your error is elsewhere. You need to supply us with a runable script that reproduces your problem.

I just find out that this problem is happen its enter the main loop command ....

while [ $temp_loop_condition -eq 0 ]
do
next_loop=0

printf "Testing1 " <- its cant pause and wait for user input
read re
....................
....................
....................
done

There is a possible solution for this problem?

>That is to avoid the automatic line feed you get at the end of an echo. In other words he wants to read the user input on the same line as the prompt.

But that can also be done with echo... (" \c" )

All the best

True, or print -n, or echo -n in some shells. Who can say which is best? :slight_smile: