On 16:38 23 Sep 2002, Spanke, Alexander <[EMAIL PROTECTED]> wrote: | Hi again, | | How can i count the lines of a text file and store it in a variable. But i | should use the bash, so no perl, python script should it be. | | Now i use | wc -l < file.txt | read dummy | | But it doesn't work :(
Others have already shown you the lines=`wc ......` incantation, but not explained why your method was failing. In your example, the "read" is happening in a subshell (because all processes in a pipeline are subprocesses), and variables are not shared between processes, merely passes from the partent to the child when the child is made. So this: a=1 echo 2 | read a echo $a will print "1". Compare this: a=1 echo 2 | { read a; echo $a; } echo $a which will print "2" from the first echo, which is in the same shell as the "read" (i.e. the {....} part) and "1" from the second echo as in the first example. -- Cameron Simpson, DoD#743 [EMAIL PROTECTED] http://www.zip.com.au/~cs/ He's silly and he's ignorant, but he's got guts, and guts is enough. - Sgt. Hartmann -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list