The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to access a variable value satish@123 Shell Programming and Scripting 4 05-19-2008 04:33 AM
PHP Shell, for secure remote access when SSH isn't available iBot UNIX and Linux RSS News 0 02-19-2008 05:50 AM
Shell access CerialPhreak UNIX for Dummies Questions & Answers 2 08-04-2006 04:07 PM
shell access, please help! genzai UNIX for Dummies Questions & Answers 4 11-18-2005 07:06 PM
Shell Access turbohacker Shell Programming and Scripting 10 03-18-2004 09:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-23-2005
sabina sabina is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 11
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 (permalink)  
Old 02-23-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
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 (permalink)  
Old 02-24-2005
sabina sabina is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 11
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0