shell variable access


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell variable access
# 1  
Old 02-23-2005
shell variable access

Hi

I want to do the following:

1. Create a number of Gloabla varibale "ROUTE_IP_xx" based on a counter. As xx sould be from 1-10.

ie ROUTE_IP_1
ROUTE_IP_2
.
.
ROUTE_IP_10

2. I want to initalize all of these variable to 0.0.0.0

ie ROUTE_IP_1='0.0.0.0'

3. I want to be able to access this global variable through out the code.
ie $ROUTE_IP_1

Following is waht I have got. I have generated the GLOBAL variable properly. But I could not figure out how to access them.

Please let me know if you have any suggestion?

Thanks,
Sabina

#!/bin/sh

ROUTE_MAX_NO_OF_ENTRY=10
count=1

while [ $count -le $ROUTE_MAX_NO_OF_ENTRY ]
do
ip_addr=ROUTE_IP_${count}
echo "ip_addr $ip_addr"
export $ip_addr='0.0.0.0'
tmp=`echo '$'$ip_addr`
echo $tmp
count=`expr $count + 1`
done
# 2  
Old 02-23-2005
Try an array:
Code:
#!/bin/ksh

ROUTE_MAX_NO_OF_ENTRY=10

# make an array with 11 (0 thru 10) elements use the last ten 
# elements

set -A ip_addr \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0' \
 '0.0.0.0'
 
# print the array 

integer i=0
while (( i <=  ${#ip_addr[*]} ))
do 
    print "ip_addr[$i]= ${ip_addr[i]}"
    let i=i+1
done

# 3  
Old 02-24-2005
Hi jim

Thanks for you reply.

I forgot to mention in my request that I am using Bourne shell and I guess arrays are not implemented in bourne shell.


Thanks,
Sabina
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Access another variable config variable

Hi all, Please help me on my problem. I want to take a value of variable which the variable is in other file. variable.sh wesly=1 wina=2 wekin=3 variabletaker.sh source variable.sh echo $wesly when i run the variabletaker.sh the error result is like here error (3 Replies)
Discussion started by: weslyarfan
3 Replies

2. AIX

ftp access without shell access

Hi all, I'm using AIX v 5.3 I want to create system users to access through ftp or sftp and restrict those users into specific directory and don't traverse the whole file system just to be restricted within a directory and don't get shell access . i don't want to use any other third party... (7 Replies)
Discussion started by: h@foorsa.biz
7 Replies

3. Shell Programming and Scripting

(solved) Shell scripting to access SQLPLUS using variable

I have shell script which will try to login to SQL Plus and retrieve some data, based on the outcome i will proceed further Below is the content of the file pebblz02% cat test1.ksh #! /bin/ksh dummyvar=`sqlplus -S csm_admin/csm_admin@SIDNAME <<EOF echo hi; exit; EOF` Error message on... (0 Replies)
Discussion started by: kiranlalka
0 Replies

4. Shell Programming and Scripting

export and access env variable in two scripts

Hi, I have two scripts say one.sh and two.sh. I want one.sh to continuously export a variable in loop. and when two.sh starts then it should read the last value exported from one.sh. file: one.sh #! bin/sh for i in `seq 1 1 4000000`; do export VAR=$(($i**$i)) ; done file two.sh ... (2 Replies)
Discussion started by: bhushan123
2 Replies

5. Shell Programming and Scripting

How to access variable from one file to another in shell script?

Hi, I had written shell script to access config file as input parameter. Contents of ConfFile.cfg are USER=ora PASSWORD=ora Shell script is DBConnect.ksh #!/bin/sh usage="`basename $0` <configuration_file_name>" DB_Connect() { sqlplus -s ora/ora << EOF CREATE TABLE TBL1... (10 Replies)
Discussion started by: Poonamol
10 Replies

6. Shell Programming and Scripting

Not access variable outside loop when a reading a file

I am writing a shell script using the korn shell. It seems that I am only able to use local variables within a while loop that is reading a file. (I can't access a variable outside a previously used while loop.) It's been a while since I wrote shell scripts. Here is a sample cat file.txt... (4 Replies)
Discussion started by: ricardo.ludwig
4 Replies

7. Shell Programming and Scripting

Unable to access variable outside loop

I am unable to access the value set inside the loop from outside loop . Thought of taking this to forum , I had seen other replies also , where a pipe takes the execution to another shell and mentioned thats the reason we do not get the variable outside loop . But I am getting an issue and I am... (1 Reply)
Discussion started by: Armaan_S
1 Replies

8. Shell Programming and Scripting

unable to access a variable not local to a while loop

I have a while loop like this cat ${filename} | while read fileline do ... done I need to access a variable value $newfile inside this while loop How will i do that?? (6 Replies)
Discussion started by: codeman007
6 Replies

9. Programming

access variable through program stack

I am working on garbage collector in C? How should :confused: I find the part of heap where the variable are stored. It there any compiler (GCC) support for this. (2 Replies)
Discussion started by: amit gangarade
2 Replies

10. Shell Programming and Scripting

how to access a variable value

hi i have a function abc() { a=1 b=2 c=3 } Now i want to assign these values to the variables out side the function k=a l=b m=c please help (4 Replies)
Discussion started by: satish@123
4 Replies
Login or Register to Ask a Question