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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error in shell script while returning values-- urgent issue plz help.
# 1  
Old 12-27-2011
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
# 2  
Old 12-27-2011
How are you assigning the return value? One way is...

Code:
function foo
{
  a=10
  return $a
}

#Function call
foo
ret=$?

echo $ret

--ahamed
# 3  
Old 12-27-2011
i am assigning as below:
CalculateEBID $FREQUENCY $BAND 1 $CELLID
TEMP_EBID=$?
T_EBID=$TEMP_EBID
# 4  
Old 12-27-2011
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...

Code:
#!/bin/bash

function foo
{
        a=10
        echo $a
}

val=$( foo )
echo $val

--ahamed
# 5  
Old 12-27-2011
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
 
 
 
# 6  
Old 12-27-2011
This seems to work... Try this...

Code:
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

Last edited by ahamed101; 12-27-2011 at 04:59 AM..
This User Gave Thanks to ahamed101 For This Post:
# 7  
Old 12-27-2011
thanks a lot ahmed for the help.
i used global variable now the scripts is fine
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. Shell Programming and Scripting

Getting error while including values in xml tags using shell script

Hi All, Please find the code below where I want to add the variable value in between the XML tags. I am taking one string and my goal is to put them between the xml tags. Ex : in between <name> , <lname> Kindly suggest a correction because while executing this script I am getting and... (8 Replies)
Discussion started by: rajneesh4U
8 Replies

3. Shell Programming and Scripting

Returning multiple values in Shell

Hi I have a code as the following #!/usr/bin/ksh set -x row() { a=$1 b=$2 c=$(($a + $b)) d=$(($a * $b)) echo $a $b } e=`row 2 3` set $e echo "The value of c is $c" echo "The value of d is $d" My requirement is I need to pass two arguments to a function and return two values... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

4. Shell Programming and Scripting

Returning to shell from previous script

Found myself stuck on this seemingly trivial issue. I have this script which call other shell files to do their deeds. The shell files in turn call some other programs as well. My problem is that in two of these shell files, the control doesnt return to next command in script unless the Enter key... (2 Replies)
Discussion started by: DoesntMatter
2 Replies

5. AIX

Need help..Urgent plz

Hi All, For listing large files i am using the following command find /XYZ/ -xdev -size +100000 |xargs ls -l |sort -nr -k 5..And my question is i am getting more number of files with this, so not able to copy those, how can I get those all in page by page , so that I can able to copy those... (4 Replies)
Discussion started by: adminaix55
4 Replies

6. Shell Programming and Scripting

shell script returning error code 2 from AIX to Mainframe

Hi, I have a shell script which is residing on AIX which is triggered by Mainframe through Connect Direct. The shell script creates several files and sends those files to mainframe using Connect Direct. The shell script is working fine, still it is returning exit code 2 to mainframe. What... (0 Replies)
Discussion started by: Yogesh Aggarwal
0 Replies

7. Shell Programming and Scripting

help in writing awk script, plz urgent

I have a file like this I have to I have input file this , I want to give the out put in the below input file (NARAYANA 1 ENDING AT (100, 16383) ,NARAYANA 2 ENDING AT (100, 32766) ,NARAYANA 3 ENDING AT (100, 49149) ,NARAYANA 4 ENDING AT (100, 65535) ,NARAYANA 5... (8 Replies)
Discussion started by: LAKSHMI NARAYAN
8 Replies

8. Shell Programming and Scripting

Returning values from child to parent shell

I need to send the status from child shell failure to parent shell. I would like to know how could we accomplish this. My parent.sh is as below: #!/bin/ksh set -x echo "I am in parent shell now..." child.sh ret_stat=$? echo "rest_stat=$ret_stat" echo "I am below parent shell end..." ... (4 Replies)
Discussion started by: acheepi
4 Replies

9. UNIX for Dummies Questions & Answers

urgent plz

guys i have sun solaries 8 under intel .. i added a new D-LINK ethernet and i need to see if the computer define it or not .. so i need to make reconfiguraion .. what was the command ... for reconfiguration ??? thanks alot (3 Replies)
Discussion started by: tamemi
3 Replies

10. Shell Programming and Scripting

Returning Values (shell Script)

I have an application on Informix 4GL, and I am invoking the shell script from the program, but I need to know if the shell script work fine or not, in order to continue the process. I know that we can use $? to get the final status but this is on unix command. How can I return a value from the... (3 Replies)
Discussion started by: jennifer01
3 Replies
Login or Register to Ask a Question