when the while loop exits, the value of (Most popular web site)
when the while loop exits, the value of $i is not preserved. In this case, you need to change a variable’s value inside the while loop and then use that value outside the loop. You can accomplish this by redirecting the STDIN prior to entering the loop and then restoring STDIN to the terminal after the while loop. The basic syntax is exec n<&0 < file while read LINE do : # manipulate file here done exec 0<&n n<&- Here n is an integer greater than 2, and file is the name of the file you want to read. Usually n is chosen as a small number such as 3, 4, or 5. As an example, you can construct a shell version of the cat command: #!/bin/sh if [ $# -ge 1 ] ; then for FILE in $@ do exec 5<&0 < "$i" while read LINE ; do echo $LINE ; done exec 0<&5 5<&- done fi Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 13: Input/Output Previous Chapter Next Chapter Sections in this Chapter: Output Summary Input Questions File Descriptors Terms Previous Section Next Section Copyright Macmillan Computer Publishing. All rights reserved.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.