script hangs when reading from stdin


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script hangs when reading from stdin
# 1  
Old 02-06-2011
script hangs when reading from stdin

script:
Code:
   while read inputline; do
   if [ "$inputline" != "" ] ; then
   if [ ! -z "`(echo $inputline | grep \#END)`" ]; then
   break
   fi
   fi
   done

Looks like the script hangs when stdin is empty or contains space. Any ideas on how to circumvent this? is it possible to use getline to process stdin content?
# 2  
Old 02-06-2011
What exactly are you trying to do with this script?
# 3  
Old 02-06-2011
I don't see any reason that should hang unless stdin does. What do you have on stdin?

For that matter -- what's your system? What's your shell? I'm sure you don't need to use grep in backticks to tell whether the string contains #END, using shell builtins will be hundreds of times faster.

Code:
#!/bin/bash

while read inputline
do
        [[ -z "${inputline}" ]] && continue
        [[ "${inputline}" == *#END* ]] && break

        echo $inputline
done < fdata

As for using getline to process input -- that also depends on your system and shell. It'd also be helpful to know what you wanted to use it for.
# 4  
Old 02-06-2011
it's KSH on AIX. trying to use the script to capture errors generated by another program into the stdin.
# 5  
Old 02-06-2011
Are you sure the program is printing them to stdout? Usually they go to stderr.

Last edited by Corona688; 02-06-2011 at 02:37 PM..
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with the Script to pass stdin in run time

I have put a script inside bash_profile of user "root". That script executes when we do "sudo su -" and prompts with a question : "Why are you logginf as root?" and users have to pass the reason then they get prompt. Inside script we have used "read -p input" to take input from user. I am a... (3 Replies)
Discussion started by: shekhar_4_u
3 Replies

2. Shell Programming and Scripting

Accept data from file or stdin in script

I have a script that looks like this:sed -f myfile.sed $1 > $1.out called myscript and would like to change it so the parameter isn't necessary: ls *.idx | myscript | xargs some_command What do I need to add so it can run either way? TIA ---------- Post updated at 09:41 AM ----------... (1 Reply)
Discussion started by: wbport
1 Replies

3. UNIX for Beginners Questions & Answers

How to use stdin as argument for script?

Say I had an extremely simple script called testScript.sh: #!/bin/sh echo $1 and I invoked it as: source testScript.sh <<< x or source testScript.sh <<< inputFile.txt When I do the above the values don't appear in the echo statement, and I know that is because in the echo... (5 Replies)
Discussion started by: steezuschrist96
5 Replies

4. Shell Programming and Scripting

Passing stdin value into a script that is called from another script

I'm trying to automatically pass user input values into a script that is being called from another script, below is my current script and I added a comment next to the script where it asks user to enter input value. Thanks, mbak #!/bin/ksh echo " Adding disks for DB server then Enter YES... (2 Replies)
Discussion started by: mbak
2 Replies

5. Shell Programming and Scripting

Suplying stdin input within script

Hi , I have script in that , i uninstall rpm using rpm -ef $rc1 now my query is rpm -ef is asking user input DO YOU Want To continue (YES/NO) for each uninstalltion. now i want to supply YES variable when it asks for above statement . so that i dont have to give user input from... (4 Replies)
Discussion started by: raghavendra.nsn
4 Replies

6. Shell Programming and Scripting

Shell script to pass multiple stdin to prorgam?

Running on AIX 5.3L. I have a program "foo" written in Fortran that requires 3 levels of inputs from stdin (command prompt). > foo Enter Input 1: a Enter Input 2: b Enter Input 3: c running foo success! > How do I get a shell script to run this automatically? > echo "a" | foo... (2 Replies)
Discussion started by: discoganya
2 Replies

7. Shell Programming and Scripting

reading from stdin in a shell script

Hello, I've managed to get my .procmailrc file to work. At least it triggers a script which creates a file. But the file is empty. How do I get at the data that's been piped? I've done much creative googling to no avail. I belive it should be in stdin, but I can't figure out how to access... (4 Replies)
Discussion started by: mmesford
4 Replies

8. Shell Programming and Scripting

Cannot redirect to STDIN in a shell script

I am unable to use STDIn redirection with < (commands) When I do the following, both approaches work and give the same results: 1. $ printf "aaa\nbbb\n" > file1 $ printf "111\n222\n" > file2 $ cat file1 file2 aaa bbb 111 2222. $ cat <(printf "aaa\nbbb\n") <(printf "111\n222\n") aaa... (8 Replies)
Discussion started by: metaltree
8 Replies

9. Shell Programming and Scripting

Script Hangs!

Hi, I have script which is based on TCL and expect. It is written to test my code. It usually runs fine for a while and hangs after sometime. Code snippet set l_temp_timeout $timeout OUTPUT_LOG2 2 >>>$expect_out(buffer)<<< OUTPUT_LOG2 2... (2 Replies)
Discussion started by: naveenpn
2 Replies

10. Programming

Help:error in reading from stdin

void redirect(int argc, char *argv) { int flag; if (strcmp(argv, ">") == 0) flag = 1; else if (strcmp(argv, "<") == 0) flag = 2; else if (strcmp(argv, ">>") == 0) flag = 3; else printf("Something Wrong,Please Check!\n"); switch (flag) {... (5 Replies)
Discussion started by: zhshqzyc
5 Replies
Login or Register to Ask a Question