[plug] function error
Jon Miller
jlmiller at mmtnetworks.com.au
Wed Jan 11 22:50:35 WST 2006
No I want to be able to read in a file (which has over a 100 names in it, each on a separate line) do a series of commands against each name. So I thought if I can get the command to read in a line do the commands and when finished read I the next and perform the same commands until it reaches the end of the file.
JLM
>>> r.steicke at bom.gov.au 10:05:54 pm 11/01/2006 >>>
On Wed, Jan 11, 2006 at 09:50:21PM +0800, Jon Miller wrote:
> I'm trying to get this function to work , what I need is for it to
> read the contents of a file and print it to screen 1 line at a time.
>
> The username2.txt file consists of a names 1 per line. I just need
> to to increment 1 name at a time which if I understand the while
> statement while line1 is less than 10 it should keep reading and
> increment by 1. Is the incrementing a built-in feature of bash
> while loop. If I'm right in C or C++ you had to have to use
> something like "line +1" or " ++line1"
There is no auto-incrementing loop in bourne shell (or bash) scripting
that I'm aware of.
What is it you're trying to do? Read the first 10 lines? Use a
separate counter to control the loop:
for counter in `seq 10` ; do
read LINE || break
# process $LINE
done < username2.txt
>
> #!/bin/bash
> # Reading lines in /etc/fstab.
> File=username2.txt
> function test {
> while [ "line1" < 10 ]; do
> {
> read line1
> } < $File
>
> done
>
> echo "First line in $File is:"
> echo "$line1"
> echo
> exit 0
> }
> test();
>
>
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
>
--
Russell Steicke
-- Fortune says:
The only difference between a rut and a grave is their dimensions.
_______________________________________________
PLUG discussion list: plug at plug.org.au
http://www.plug.org.au/mailman/listinfo/plug
Committee e-mail: committee at plug.linux.org.au
More information about the plug
mailing list