Sponsored Content
Top Forums Shell Programming and Scripting Read from user inside a while statement Post 302495832 by kshji on Friday 11th of February 2011 10:22:44 AM
Old 02-11-2011
Code:
read_write () 
{
echo -n "Do you want to print the line (Y/N)?"
<&5 read  TEST   # input from handler 5 = org. stdin
case "$TEST" in
        Y) return 0;;
        N) return 1;;
        *) read_write;;
esac
}

exec 4< ./test.txt  # handler 4 for file
exec 5<&1    # handler 5 is same as stdin handler 1
while read line   
do
        echo $line      # stdout
        read_write
done <&4

This User Gave Thanks to kshji For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exit statement ignored inside KSH function

Hi All, I have multiple functions in my script and I'm trying to capture stdout from some of them, but I also do some error checking in them (in the functions that output something to their stdout that needs capturing) and I need to be able to end the entire script with an error message. ... (2 Replies)
Discussion started by: gkubok
2 Replies

2. Shell Programming and Scripting

if inside while statement (PLZ HELP)

hey guys i need some help here i am trying to do a bash shell script to get a parent PID and then search for all childs and kill them all without killing the parent, my problem is in the loop it seems that i dont know how to make a if statment inside a while statment it does not give me what i... (5 Replies)
Discussion started by: q8devilish
5 Replies

3. Shell Programming and Scripting

Sysdate inside awk print statement

Hi, I am using awk statement to extract data from a file and write a new file with certain columns rearranged and few hard coded values added to new file. Now i need to add a column with sysdate. can i do that inside the awk print statement? Now: nawk ' /^3/ BEGIN {FS=","}... (2 Replies)
Discussion started by: selvankj
2 Replies

4. Shell Programming and Scripting

Multiple conditions inside my if statement

Hello, I am using shell scripting and I am recieving odd results from my if statement if I want it to enter the loop only if L1 is equal to zero and one of the other criteria are filled, however it is entering at other times as well. What can i do to fix this? i tried seperating it... (6 Replies)
Discussion started by: ryddner
6 Replies

5. Shell Programming and Scripting

issues with sql inside if statement

Hi, I have problem with the following code. My IF block is not executed. And I see "syntax error near unexpected token `)'" error for line "EOF" in the stats_function(). but when I comment the IF block I don't see this error. Kindly help me with this issue. clean_function() {... (10 Replies)
Discussion started by: babom
10 Replies

6. Homework & Coursework Questions

How to read user keyboard input inside the case?

I need to Write a shell script that allows some system-administration tasks to be preformed automatically from a menu-driven interface. with automated following tasks: Copy directory tree Delete files or directories Output Information (this part is done ) *Copy directory tree The “Copy... (2 Replies)
Discussion started by: femchi
2 Replies

7. Shell Programming and Scripting

Multiple conditions inside if statement

I was trying to write multiple conditions inside the if statement but its not working. export VAR_NM=abc.txt export CURR_DT=20131011 export PREV_DT=20131012 if && then echo "Yes" else echo "NO" fi It should return Yes but returning NO always.Appreciate any help. (3 Replies)
Discussion started by: dr46014
3 Replies

8. Shell Programming and Scripting

Command in inside awk statement

Hello can you please help me with below script which is meant to delete clients from multiple netbackup policies I want to run a command insdie awk statement apparelnlty this script is not working for me for i in $( cat clients_list) do bppllist -byclient $i | awk... (6 Replies)
Discussion started by: Sara_84
6 Replies

9. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies
STREAM_FILTER_PREPEND(3)						 1						  STREAM_FILTER_PREPEND(3)

stream_filter_prepend - Attach a filter to a stream

SYNOPSIS
resource stream_filter_prepend (resource $stream, string $filtername, [int $read_write], [mixed $params]) DESCRIPTION
Adds $filtername to the list of filters attached to $stream. PARAMETERS
o $stream - The target stream. o $filtername - The filter name. o $read_write - By default, stream_filter_prepend(3) will attach the filter to the read filter chain if the file was opened for reading (i.e. File Mode: r, and/or +). The filter will also be attached to the write filter chain if the file was opened for writing (i.e. File Mode: w, a, and/or +). STREAM_FILTER_READ, STREAM_FILTER_WRITE, and/or STREAM_FILTER_ALL can also be passed to the $read_write parameter to override this behavior. See stream_filter_append(3) for an example of using this parameter. o $params - This filter will be added with the specified $params to the beginning of the list and will therefore be called first during stream operations. To add a filter to the end of the list, use stream_filter_append(3). RETURN VALUES
Returns a resource which can be used to refer to this filter instance during a call to stream_filter_remove(3). CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Prior to PHP 5.1.0, this function returns TRUE | | | on success or FALSE on failure. | | | | +--------+---------------------------------------------------+ NOTES
Note When using custom (user) filters stream_filter_register(3) must be called first in order to register the desired user filter to $filtername. Note Stream data is read from resources (both local and remote) in chunks, with any unconsumed data kept in internal buffers. When a new filter is prepended to a stream, data in the internal buffers, which has already been processed through other filters will not be reprocessed through the new filter at that time. This differs from the behavior of stream_filter_append(3). Note When a filter is added for read and write, two instances of the filter are created. stream_filter_prepend(3) must be called twice with STREAM_FILTER_READ and STREAM_FILTER_WRITE to get both filter resources. SEE ALSO
stream_filter_register(3), stream_filter_append(3). PHP Documentation Group STREAM_FILTER_PREPEND(3)
All times are GMT -4. The time now is 01:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy