Help needed in bourne script..

Hi Guys,

This is my first script, even though i have made corrections in others scripts., this is the first one I am writing from the scratch..

#! /bin/sh
prev_Ixref=245
curr_Ixref=355
while ( ($prev_Ixref -lt 245)&&($prev_Ixref -gt 355))
do
echo "curr_Ixref is $curr_Ixref"
echo "prev_Ixref is $prev_Ixref"
curr_Ixref=curr_Ixref+1
prev_Ixref=prev_Ixref+1
done

When i ran this script after giving execute permissions, i am getting
a.sh[6]: 245: not found.

could anyone help me.. its urgent..once this logic works i have to make suitable modifications..

Thanks in advance,
Magesh

write

You seem to have forgotten the quotes around variables and numbers :slight_smile:

Hi Guys,

THanks for the quick response,,

I have changed the code..
#! /bin/sh
prev_Ixref=245
curr_Ixref=355
while ("$prev_Ixref" -lt "245" -a "$prev_Ixref" -gt "355")
do
echo "curr_Ixref is $curr_Ixref"
echo "prev_Ixref is $prev_Ixref"
curr_Ixref=curr_Ixref+1
prev_Ixref=prev_Ixref+1
done

Still it is giving the same error..
could you please help me out..:frowning:

use [

You are still using round parentheses in the while although viyadhar85 already pointed out how to correct it.

("$prev_Ixref") in round parentheses means run the command "$prev_Ixref" in a subshell. That's not what you want.

The syntax of the while loop is while command; do ... done and the command should be your comparison test. The [ command (sic) is also known as test and is used to perform arithmetic comparisons (among a number of other things).

Thanks guys,, for your help..
The script ran successfully..
but i am not getting output which should have come from the echo statement..

When i ran the script, it immediately gives the prompt without any outputs.

could you please help me to see how many times the loop executes..

Thanks in advance

The way you set it up, it's not less than 245, so this should hardly be surprising. It's also not clear under what circumstances you could expect the same number to be less than 245 and greater than 355 at the same time. What do you want it to do, exactly?

you can't increment the variable in this way..

use

Thanks vidyadar for pointing out that..

Era,
Thanks tats the mistake on my part..
it should be

while [ "$prev_Ixref" -gt "245" -a "$prev_Ixref" -lt "355" ]
like this..
thanks for that..
currently i am having a problem in network..once its done.. i ll let u knw the results..

Thanks once again..

guys, the script ran successfully guys,,
no i ll start to build my actual requirements on it..
guys actually i have to update a column..
the column is a number which is auto generated..

Lets say the column is currently having 245,
then i have to update it with 355..

so in the place of echo.. i am goin to write this code..

db2 -v "update tablename set column_name = $prev_Ixref \
where column_name= $curr_Ixref "

can u please help me out with this..

then why are you checking for greater and less than??
and that update statement should work.. you can write full update statement in single line..

i have les idea about db2 sorry ..

vidayadhar,, am talkin abt updating 8 crore records, which i cant do it in a single go,,
so i have to do it only 5 lakh records at a time..
i will do a commit after that and repeat the update query again..

Anyway thanks vidayadar

yes ofcourse you can update any no of rows..
but as you said

i din't get how this condition is satisfied by your script??

Vidyadar,

ya, there is a mistake again(silly mistakes often happen to me), again i have to swap the curr and prev values in teh update queries..

I hadn't heard crore before -- perhaps it would be wise to avoid regional jargon.

It's not really clear how your small script relates to the problem in question. You want to issue 50,000 commands to increment an index by 110, then commit, repeat 160 times?

for base in 245 50245 100245; do  # add 157 more or write another loop ...
  perl -le 'for (0..49999) {
    print "update whatever where value ", $ARGV[0]+$_, " with value ", $ARGV[0]+$_+110 }' $base |
  less # replace with db2 if this looks correct
done