error in shell script while returning values-- urgent issue plz help.

Hi,

I have initailized a varaible EBID as typeset Long EBID=0

i am calculating value of EBID using certian formula as below:
(( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE ))
return $CURR_EBID

The output is as below:
+ (( CURR_EBID= (15 << 27) | (125 << 16) | (135 << 4) | 1 ))
+ return 2021460081
+ TEMP_EBID=113
-----------------------------

the value after calculation is correct. But the value stored after returing is wrong.
The above script returns 2021460081 but the value stored is 113.

I m not understanding the error.

can anyone plz let me know error?

its urgent

--sailaja

How are you assigning the return value? One way is...

function foo
{
  a=10
  return $a
}

#Function call
foo
ret=$?

echo $ret

--ahamed

i am assigning as below:
CalculateEBID $FREQUENCY $BAND 1 $CELLID
TEMP_EBID=$?
T_EBID=$TEMP_EBID

That looks fine.

Can you paste few more lines of the code around the function and function call. Also, please post the trace.

Meantime, you can try this way also...

#!/bin/bash

function foo
{
        a=10
        echo $a
}

val=$( foo )
echo $val

--ahamed

This is the fulls cript:
#!/bin/sh

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#
# In the BTSTemplate -
#
# Replace all instances of the BTS name/ CELL name with "@BTSNAME"
# Replace Traffic Range value with "@TRAFFICRANGE" (METROINV/COMPACTINV)
# Replace Port Number value with "@PORTNUMBER" (METROINV/COMPACTINV)
# Replace CEll ID with "@CELLID" (MSECTOR)
# Replace IP Adress with "@IPADDRESS" (BTSIWFPORT)
# Replace INSASPI with "@SASPI" (BTSIWFPORT & ETHERNETINV)
# Replace EGSASPI with "@SASPI" (BTSIWFPORT & ETHERNETINV)
#
# The BTSTemplate should not contain section adding a new LogicalIPPort
#
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
### CONSTANTS ###
HOME="/export/home/bsmbin/" # home directory of the user who is running this script.
BTS_TEMPLATE="new.txt" #input cli template with the token substitution.
FINAL_BATCHFILE="default_finalbatchfile1.cli" # output bsmci batch file location
BTS_COUNT=1 # number BTSs to be created
CELLID=135 #starting cell id number
PORTNUM=40 # starting portnumber
TRAFFICRANGE=11 # starting Traffic range...
typeset String BAND=AWS #
typeset Integer FREQUENCY=125 # starting the fourth element in an IP Address
SECTOR_VALUE=1
TotalSECTOR_COUNT=3
typeset Long EBID=0
typeset Long NeighbourOne=0
typeset Long NeighbourTwo=0
typeset Long ACNID=0
PILOT=24
TRAFFICRANGE_GROUP=4

### FUNCTIONS ###

#####################################################
#Function to change the value of
#BTS Template
#####################################################
CalculateACNId()
{
CURR_TR=$3
CURR_PORT=$1
CURR_TRM=262144
CURR_PM=2048
CURR_OFFSET=49
CURR_TRG=$2
(( CURR_ACNID= ($CURR_TRG << 24) + ($CURR_TR * $CURR_TRM) + ($CURR_PORT * $CURR_PM) + $CURR_OFFSET ))
return $CURR_ACNID
}

#####################################################
#Function to change the value of
#BTS Type
#####################################################
CalculateEBID ()
{
typeset Integer CURR_CELLID=$4
typeset Integer CURR_SECTOR_VALUE=$3
typeset String CURR_BAND=$2
typeset Integer CURR_FREQ=$1
case $CURR_BAND
in
800)BANDINDEX=0 ; ;;
1900)BANDINDEX=1 ; ;;
450)BANDINDEX=5 ; ;;
AWS)BANDINDEX=15 ; ;;
SEC_800)BANDINDEX=10 ; ;;
esac
(( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE ))
return $CURR_EBID
}

####################################################
#
# MAIN PROGRAM
#
####################################################

### GENERATE Batch File ###
### INITIALIZE VARIABLES###
count=0
btscount=0
COUNT=$TotalSECTOR_COUNT
### LOOP ###

/usr/bin/chmod 775 $FINAL_BATCHFILE
echo "#New PDB scripts" >> $FINAL_BATCHFILE
echo "edit O%:CBS1:SystemConfiguration1:SystemPilotDatabase1" >> $FINAL_BATCHFILE
echo " (PDBTable = " >> $FINAL_BATCHFILE
echo "($TotalSECTOR_COUNT, " >> $FINAL_BATCHFILE
while [ $btscount -lt $BTS_COUNT ]
do

CUUR_SEC_COUNT=1
CalculateEBID $FREQUENCY $BAND 1 $CELLID
TEMP_EBID=$?
Alpha_EBID=$TEMP_EBID
CalculateEBID $FREQUENCY $BAND 2 $CELLID
TEMP_EBID=$?
Beta_EBID=$TEMP_EBID
CalculateEBID $FREQUENCY $BAND 3 $CELLID
TEMP_EBID=$?
Gamma_EBID=$TEMP_EBID
CalculateACNId $PORTNUM $TRAFFICRANGE_GROUP $TRAFFICRANGE
ACNID=$?
while [ $CUUR_SEC_COUNT -lt 4 ]
do
case $CUUR_SEC_COUNT
in
1) EBID=$Alpha_EBID; N_one=$Beta_EBID; N_two=$Gamma_EBID;
/usr/bin/cat $HOME$BTS_TEMPLATE | /usr/bin/sed 's/@COUNT/'$COUNT' /' | /usr/bin/sed 's/@VALUE/'$count' /' |
/usr/bin/sed 's/@EBID/'$EBID' /' | /usr/bin/sed 's/@ACNID/'$ACNID' /' |
/usr/bin/sed 's/@PILOT/'$PILOT' /' | /usr/bin/sed 's/@NeighbourOne/'$N_one' /' |
/usr/bin/sed 's/@NeighbourTwo/'$N_two' /' >> $FINAL_BATCHFILE ;
count=`expr $count + 1` ;
;;
2) EBID=$Beta_EBID; N_one=$Alpha_EBID; N_two=$Gamma_EBID; PILOT=`expr $PILOT + 4`;
/usr/bin/cat $HOME$BTS_TEMPLATE | /usr/bin/sed 's/@COUNT/'$COUNT' /' | /usr/bin/sed 's/@VALUE/'$count' /' |
/usr/bin/sed 's/@EBID/'$EBID' /' | /usr/bin/sed 's/@ACNID/'$ACNID' /' |
/usr/bin/sed 's/@PILOT/'$PILOT' /' | /usr/bin/sed 's/@NeighbourOne/'$N_one' /' |
/usr/bin/sed 's/@NeighbourTwo/'$N_two' /' >> $FINAL_BATCHFILE ;
count=`expr $count + 1` ;
;;
3) EBID=$Gamma_EBID; N_one=$Beta_EBID; N_two=$Alpha_EBID; PILOT=`expr $PILOT + 4`;
/usr/bin/cat $HOME$BTS_TEMPLATE | /usr/bin/sed 's/@COUNT/'$COUNT' /' | /usr/bin/sed 's/@VALUE/'$count' /' |
/usr/bin/sed 's/@EBID/'$EBID' /' | /usr/bin/sed 's/@ACNID/'$ACNID' /' |
/usr/bin/sed 's/@PILOT/'$PILOT' /' | /usr/bin/sed 's/@NeighbourOne/'$N_one' /' |
/usr/bin/sed 's/@NeighbourTwo/'$N_two' /' >> $FINAL_BATCHFILE ;
count=`expr $count + 1` ;
;;

esac
CUUR_SEC_COUNT=`expr $CUUR_SEC_COUNT + 1`
done
### INCREMENT VARIABLES ###
btscount=`expr $btscount + 1`

done
echo " ));" >> $FINAL_BATCHFILE
echo "exit ;" >> $FINAL_BATCHFILE
exit

This seems to work... Try this...

CalculateEBID ()
{
        typeset Integer CURR_CELLID=$4
        typeset Integer CURR_SECTOR_VALUE=$3
        typeset String CURR_BAND=$2
        typeset Integer CURR_FREQ=$1
        case $CURR_BAND
        in      
          800)BANDINDEX=0 ; ;;
          1900)BANDINDEX=1 ; ;;
          450)BANDINDEX=5 ; ;;
          AWS)BANDINDEX=15 ; ;;
          SEC_800)BANDINDEX=10 ; ;;
        esac
        (( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE ))
        echo $CURR_EBID
}
...

TEMP_EBID=`CalculateEBID $FREQUENCY $BAND 1 $CELLID`

Not sure why the other didn't work, may be something to do with the shell? I am also getting the same 113.

--ahamed

---------- Post updated at 12:50 AM ---------- Previous update was at 12:42 AM ----------

I think the return value range is 0 - 255.
You can try it youself. Upto 255, it is returning correctly, post 255 it starts from 0 again.

So, either

  1. Use a global variable and capture the value
  2. Use the solution in post i.e. alternate way to capture return val

HTH
--ahamed

1 Like

thanks a lot ahmed for the help.
i used global variable now the scripts is fine