the shell not pause when execute read command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting the shell not pause when execute read command
# 8  
Old 07-03-2008
Quote:
Originally Posted by Annihilannic
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
# 9  
Old 07-04-2008
vbe,

Quote:
Originally Posted by vbe
Maybe silly question :
Why "printf "Please ..."
All your other lines, you used echo...
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?

Code:
$ ./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 : []
...

# 10  
Old 07-04-2008
Quote:
Originally Posted by Annihilannic
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?

Code:
$ ./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...
# 11  
Old 07-04-2008
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...
# 12  
Old 07-04-2008
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....
Code:
$ 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.
# 13  
Old 07-04-2008
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?
# 14  
Old 07-04-2008
>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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Process to read a new file entry and execute a command

I need to develop a process/daemon which will constantly monitor a file for new entry and execute a command. for eg, there is a file /var/log/inotify.log When a new entry like below gets appeneded to this file, execute the command as follows. /home/user/public_html/bad.php|CREATE ... (2 Replies)
Discussion started by: anil510
2 Replies

2. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

3. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

4. UNIX for Dummies Questions & Answers

How to execute command after telneting in shell script?

Hi , I have to write a shell script to telnet to specific host and execute the admin command there. Please help me to do that. Eg : telnet hostname portno admin command exit (3 Replies)
Discussion started by: arukuku
3 Replies

5. Shell Programming and Scripting

How to pause a shell script

Hi, I've written a shell script to take photos with my camera. After every picture taken, the picture is transmitted to the computer via usb and then deleted on the camera. But sometimes there's an error and the picture is not deleted and so, after a certain time, the camera chip will be... (4 Replies)
Discussion started by: McLennon
4 Replies

6. Shell Programming and Scripting

Cann ot execute a shell command

Hi , I am new to UNIX and Shell scripting . I am not able to execute a shell file . I try to do it using the below command. ./start.sh but it shows an error that 'cannot execute ' what might be the reason for this? pls help me to resolve it. (1 Reply)
Discussion started by: Deepakkumard
1 Replies

7. Shell Programming and Scripting

shell script to execute user command

I don't know why the following shell script doesn't work. Could you please help me out? #!/usr/bin/ksh test="cal > /tmp/tmp.txt 2>&1" $test I know it will work for the following format: #!/usr/bin/ksh cal > /tmp/tmp.txt 2>&1 However, I need to get the command from the user in... (1 Reply)
Discussion started by: redtiger
1 Replies

8. Shell Programming and Scripting

execute a command silently or quietly within a shell

How do I suspend output of commands and tools that sometimes utter unwanted output? I know that I can always pipe to null or some such thing, but is there a simpler more elegant (i.e. accepted) practice? (4 Replies)
Discussion started by: lumix
4 Replies

9. UNIX for Dummies Questions & Answers

pause needed for corn shell

I need a user pause for a script file, like the pause command in dos. please help I thought it was the corn shell it is csh. (7 Replies)
Discussion started by: dennysavard
7 Replies

10. Shell Programming and Scripting

execute shell command in perlscript

Hi I have this below script...I want to execute the shell command "rm" in the below script but it is not working. Can anybody why so? I got the below error rm: /users/amvarma is a directory sh: /*-log*: not found ------------------- $u=`whoami`; print "$u\n"; $op_1=$ARGV; # for... (0 Replies)
Discussion started by: amitrajvarma
0 Replies
Login or Register to Ask a Question