I have a list of values (currently about 80 in a file) which I need to process in a Bourne Shell script and then use each value to execute another shell script.
If I use the construct
read parameter
do
some processing
call other shell script using parameter
done < data_file.lst
then whatever code is executed in the do done loop does not have a tty associated with it. This means that the shell script which gets called which tests for tty to do some tput processing will not work.
I do not want to use for parameter in `cat data_file.lst`
method which retains stdin and stdout connected to the tty, because there is the danger that as the list of values grows, the maximum line length will be eventually be exceeded.
So can anybody sugge开发者_开发技巧st a method for processing a list of parameters without using read do done?
Or will it have to be the use of xargs to call an intermediate shell script to do the processing and then that calls the secondary shell scripts?
# Make copy of stdin.
exec 3<&0
while read parameter; do
some processing
# In sub-shell restore original stdin, then execute command.
(exec 0<&3; command that needs tty)
done < data_file.lst
Use a different file handle for your read:
while read parameter <&3
do
some processing
call other shell script using parameter
done 3< data_file.lst
精彩评论