[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: error in script

L.V.Gandhi wrote:
On Fri, Sep 5, 2008 at 8:00 AM, David Parker <dparker@utica.edu <mailto:dparker@utica.edu>> wrote:

    ----- Original Message -----
    From: "L.V.Gandhi" <lvgandhi@gmail.com <mailto:lvgandhi@gmail.com>>
    Date: Thursday, September 4, 2008 9:50 pm
    Subject: error in script
    To: debian-user <debian-user@lists.debian.org

     > I have a script as follows
     > #!/bin/bash
     > rm -f ~/stock/flstock.csv
     > grep FUTSTK ~/stock/today/$1 |grep "25/09/2008"|cut -s -d,
    -f9|sort -nr > temp
     > i=0
     > for trv in $(cat temp)
     > do
     >     grep $trv ~/stock/today/$1 >> ~/stock/flstock.csv
     >     i=$((i+1))
     >     if [ $i -eq 20 ]
     >     then
     >     exit 0
     >     fi
> done > rm -f temp
     > cat ~/stock/flstock.csv |cut -s -d, -f2|sort >>

     > Last line is not getting  executed . But if I run last line
    afterwards in console, it works.
     > Can someone throw somelight why it happens.

    Try echoing the value of $i each time through the loop.  I wonder if
    the "exit 0" when $i = 0 is the problem.

        - Dave

Thanks. I think you are correct. What should do to come out of loop instead of exiting the script.

If you only want the loop to run 20 times, then you can change it to only read a maximum of 20 lines from the file:

for trv in $(head -n20 temp)

    - Dave


Dave Parker
Utica College
Integrated Information Technology Services
(315) 792-3229
Registered Linux User #408177

Reply to: