From: srikanth on
On May 31, 8:21 am, Bit Twister <BitTwis...(a)mouse-potato.com> wrote:
> On Sun, 30 May 2010 19:08:01 -0700 (PDT), srikanth wrote:
> > BTW, when i change to a while loop it is showing HEAD usage at the end
> > of the script execution.
> > Am i using HEAD in a wrong way?
>
> I can only guess last line(s) of the input file is not what
> head expected.

Yes, there is a blank line at the EOF that's why it is showing HEAD
usage. But it is not showing if i use for loop.
Is there will be any diff in between them in shell?
From: Bit Twister on
On Sun, 30 May 2010 20:56:08 -0700 (PDT), srikanth wrote:
>
> Yes, there is a blank line at the EOF that's why it is showing HEAD
> usage.

Going to guess it really is two blank lines. :)
It is the last one which exits the while loop, and the next to last
which cause the error.

> But it is not showing if i use for loop.

Yes, the extra line made extra white space, which never showed up
in i.

> Is there will be any diff in between them in shell?

Question is kind of vague. You have already proven code runs
differently for a while/for loop.

Solutions,
o Continue to use your for solution and hope expanded cat line does
not fail in the future.
o You fix the input to be terminated by one line only, instead of two.
o Use an if statement around HEAD, if i is not empty.
Hint man test and watch for -n
From: srikanth on
On May 31, 11:55 am, Bit Twister <BitTwis...(a)mouse-potato.com> wrote:
> On Sun, 30 May 2010 20:56:08 -0700 (PDT), srikanth wrote:
>
> > Yes, there is a blank line at the EOF that's why it is showing HEAD
> > usage.
>
> Going to guess it really is two blank lines.   :)
> It is the last one which exits the while loop, and the next to last
> which cause the error.
>
> > But it is not showing if i use for loop.
>
> Yes, the extra line made extra white space, which never showed up
> in i.
>
> > Is there will be any diff in between them in shell?
>
> Question is kind of vague. You have already proven code runs
> differently for a while/for loop.
>
> Solutions,
> o Continue to use your for solution and hope expanded cat line does
>   not fail in the future.
> o You fix the input to be terminated by one line only, instead of two.
> o Use an if statement around HEAD, if i is not empty.
>   Hint       man test    and watch for -n

At last I have tried and got the script working as per my requirement.
From: srikanth on
On May 31, 12:50 pm, srikanth <srikanth0...(a)gmail.com> wrote:
> On May 31, 11:55 am, Bit Twister <BitTwis...(a)mouse-potato.com> wrote:
>
>
>
> > On Sun, 30 May 2010 20:56:08 -0700 (PDT), srikanth wrote:
>
> > > Yes, there is a blank line at the EOF that's why it is showing HEAD
> > > usage.
>
> > Going to guess it really is two blank lines.   :)
> > It is the last one which exits the while loop, and the next to last
> > which cause the error.
>
> > > But it is not showing if i use for loop.
>
> > Yes, the extra line made extra white space, which never showed up
> > in i.
>
> > > Is there will be any diff in between them in shell?
>
> > Question is kind of vague. You have already proven code runs
> > differently for a while/for loop.
>
> > Solutions,
> > o Continue to use your for solution and hope expanded cat line does
> >   not fail in the future.
> > o You fix the input to be terminated by one line only, instead of two.
> > o Use an if statement around HEAD, if i is not empty.
> >   Hint       man test    and watch for -n
>
> At last I have tried and got the script working as per my requirement.

One more thing here i want to know here.. How to add a progress bar to
show the current status of the running script
From: Bit Twister on
On Tue, 1 Jun 2010 21:34:10 -0700 (PDT), srikanth wrote:
>
> Just i need a progress bar some thing like 'Browsing URLs...' here the
> dots should show the progress bar.
> some thing like . . . again it should start . . .
> I think you understood my question? So how can i implement this
> technique in my script?

I gave an example using printf "*"
If you want a period, use printf "."

Here save and run this
#!/bin/bash
_counter=0
_percentage=1
for i in 1 2 3 4 5 6 7 8 9 10 ; do
let _counter="_counter + 1"
if [ $_counter -gt $_percentage ] ; then
printf "."
_counter=0
sleep 1
fi
done
printf "\n"