FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 05-14-2008, 12:51 AM
L.V.Gandhi
 
Default bash doubt

I have a script as follows
lvgandhi@lvghomepc:~$ cat bin/getlstocks
#!/bin/bash
i=0
while [ $i -ne 20 ]
do
for trv in $(cat temp)
do
i=$i+1
grep $trv stock/nsedata/2008/05/20080512.txt >> lstock
done
done
when I run I get error as
integer expression expected
How to correct it

--
L.V.Gandhi
http://lvgandhi.tripod.com/
linux user No.205042


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-14-2008, 01:05 AM
"Jordi Gutiérrez Hermoso"
 
Default bash doubt

On 13/05/2008, L. V. Gandhi <lvgandhi@gmail.com> wrote:
> I have a script as follows
[snip]
> i=$i+1
[snip]
> How to correct it

Your counter is wrong. $i + 1 means to treat i as a string and to
append the string "1" to it. If you want to do arithmetic in bash, you
have to put it inside brackets. i = $[i+1].

Btw, an easier way to do a for loop of this sort in bash is to do "for
i in `seq 20`" (notice the backticks).

If you want to do a lot of text manipulation, it may feel more natural
to use Perl (or at least it feels more natural to me).

- Jordi G. H.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-14-2008, 02:13 AM
"Douglas A. Tutty"
 
Default bash doubt

On Tue, May 13, 2008 at 08:05:16PM -0500, Jordi Guti?rrez Hermoso wrote:

> If you want to do a lot of text manipulation, it may feel more natural
> to use Perl (or at least it feels more natural to me).

Or Python. Or Ada.

Almost anything but sh.

Doug.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-14-2008, 03:24 AM
"Todd A. Jacobs"
 
Default bash doubt

On Wed, May 14, 2008 at 06:21:07AM +0530, L.V.Gandhi wrote:

> i=$i+1

This syntax is broken. Any of these alternatives will work:

- let i=$i+1
- let i+=1
- i=$(( i + 1 ))

Basically, you need to let bash know that $i is an integer, and not a
string.

--
"Oh, look: rocks!"
-- Doctor Who, "Destiny of the Daleks"


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-14-2008, 11:13 PM
Michelle Konzack
 
Default bash doubt

Am 2008-05-14 06:21:07, schrieb L.V.Gandhi:
> I have a script as follows
> lvgandhi@lvghomepc:~$ cat bin/getlstocks
> #!/bin/bash
> i=0
> while [ $i -ne 20 ]
> do
> for trv in $(cat temp)
> do
> i=$i+1
i=$((i+1))

Thanks, Greetings and nice Day
Michelle Konzack
Systemadministrator
24V Electronic Engineer
Tamay Dogan Network
Debian GNU/Linux Consultant


--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
+49/177/9351947 50, rue de Soultz MSN LinuxMichi
+33/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)
 
Old 05-15-2008, 12:58 AM
L.V.Gandhi
 
Default bash doubt

On Wed, May 14, 2008 at 8:54 AM, Todd A. Jacobs <nospam@codegnome.org> wrote:
> On Wed, May 14, 2008 at 06:21:07AM +0530, L.V.Gandhi wrote:
>
>> i=$i+1
>
> This syntax is broken. Any of these alternatives will work:
>
> - let i=$i+1
> - let i+=1
> - i=$(( i + 1 ))
>
> Basically, you need to let bash know that $i is an integer, and not a
> string.
>
Now I changed this to
rm -f ~/lstock
i=0
for trv in $(cat temp)
do
while [ $i -ne 20 ]
do
i=$[i+1]
grep $trv stock/nsedata/2008/05/20080512.txt >> lstock
done
done
I get lstock only 0 byte file.
Where am I wrong

--
L.V.Gandhi
http://lvgandhi.tripod.com/
linux user No.205042


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-15-2008, 07:01 AM
Ansgar Esztermann
 
Default bash doubt

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Where am I wrong


By the way, you might want to call your script as
bash -x scriptname

This will run the script in trace mode, much facilitating debugging.
You might also set PS4 to something sensible first. Personally, I
prefer PS4='+$0 l $LINENO: '



A.
- --
Ansgar Esztermann
DV-Systemadministration
Max-Planck-Institut für biophysikalische Chemie, Abteilung 105

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAkgr37kACgkQYmVfELZx7BpkwwCgos6hRSOzpj 9PgBzAzpkDyVzN
94QAoO6iqIMnGtH87c2FxuSpTELKtUoY
=wR08
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-15-2008, 11:48 AM
"Javier Barroso"
 
Default bash doubt

On Thu, May 15, 2008 at 2:58 AM, L. V. Gandhi <lvgandhi@gmail.com> wrote:



Now I changed this to

rm -f ~/lstock

i=0

for trv in $(cat temp)

do

* * * *while [ $i -ne 20 ]

* * * *do

* * * * * * * *i=$[i+1]

* * * * * * * *grep $trv stock/nsedata/2008/05/20080512.txt >> lstock

* * * *done

done

I get lstock only 0 byte file.Hi,
which is the "temp" file content ?

why are you using $i loop? , trv doesn't change inside it ...
 
Old 05-15-2008, 11:50 AM
"Javier Barroso"
 
Default bash doubt

On Wed, May 14, 2008 at 3:05 AM, Jordi Gutiérrez Hermoso <jordigh@gmail.com> wrote:

On 13/05/2008, L. V. Gandhi <lvgandhi@gmail.com> wrote:

> I have a script as follows

[snip]

> * * * * * * * * i=$i+1

[snip]

> *How to correct it



Your counter is wrong. $i + 1 means to treat i as a string and to

append the string "1" to it. If you want to do arithmetic in bash, you

have to put it inside brackets. i = $[i+1].*You should use i=$((i+1))

In man bash:
*The old format $[_expression_] is deprecated and will be removed in upcoming versions of bash.
 
Old 05-16-2008, 06:55 PM
"Bernardo Dal Seno"
 
Default bash doubt

2008/5/15 L. V. Gandhi <lvgandhi@gmail.com>:
> Where am I wrong

With the knowledge of the content of your files it is easier to
answer. Running the script in trace mode is the best thing to do.

Anyway, I see that there are two problems here (which may or may not
be related to your problem):

> for trv in $(cat temp)

If expressions in `temp' contain spaces, they will be broken; this
would be better:
while read trv; do
....
done < temp


> grep $trv stock/nsedata/2008/05/20080512.txt >> lstock

$trv should be quoted, like this:
grep "$trv" ...


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 11:33 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org