It is currently Tue, 17 May 2022 01:22:42 GMT

Author Message
 Double Variables in a Shell Script - Help Please

OS=HP-UX 11.11, K Shell Script

Not sure I am doing it correct, basically I am trying to avoid CASE and
lengthy code if possbile.

Here is what I want to do:

PORT_NUMBER="2100 2300 2400 2500"

# Get the Queues for each Port. A port can have multipile queues
# Each queue  can be queried for  "TOTAL, BACKLOG, Inserts, Updates
Deletes, etc.,"

for Port in $PORT_NUMBER
    Queue${Port}=$(echo " port $Port \n qstatus " |sp_ctrl |egrep -i
Name |cut -f5 -d" ")
     # I expect Queue2100=A1_queue A2_queue A3_queue
     # Queue2200=B1_queue  B2_queue
     # Que2300=C1_queue
     # Queue2400=D1_queue  D2_queue  D3_queue
     # each port can have multiple queues
     # Process each Queue Elements one by one
      for Queue in ${QUEUE${Port}}                       # This is not
working ????
          set -A B $(echo "port $Port  \n  show post queue $Queue
detail" lsp_ctrl |           egrep -i
          # set the port to 2100 and  Query the gien Queue and assing
it to Array B
          #sp_ctrl is the executable
          echo ${B[*]}
           # Manipulate Array B to generate an Insert statement into an
oracle Database
           # I have the Code working for this. Collect Insert Statement
for each port and its       Queues

            cat <<EOF >>bn1.sql
insert into system.nnos_splex_stats

 to_date('${B[3]} ${B[4]}','mm/dd/yyyy hh24:mi:ss'),

done   # end of For loop for all the Queues for a given port
done   # end of for loop for given ports

Appreciate your Help and Suggestions

Regards & Thanks

 Sat, 25 Oct 2008 08:32:03 GMT   
 Double Variables in a Shell Script - Help Please

Some hints:
o take a look at and/or "play"(/test) with eval
o use small test sets and bits of script, and use the -v and -x
  options to help better understand how the shell is parsing,
  interpreting, and processing your script
o use/consider array variables (as long as you're using Korn or
  reasonably compatible shell)
o keep in mind the order in which the shell interprets and applies
  various substitutions.

$ n=5
$ foo${n}=50
ksh: foo5=50: not found
$ eval foo${n}=50
$ echo $foo5

 Sat, 25 Oct 2008 09:57:39 GMT   
 Double Variables in a Shell Script - Help Please

To make the assignment, under AIX and ksh88 or ksh93, i use:


Then to use the variable I use:


This works much better under ksh93 than ksh88 I've found.


 Sat, 25 Oct 2008 23:59:14 GMT   
   [ 3 post ] 

Similar Threads

1. file contents into variable, or global variable from shell script

2. Double dereferencing Bourne shell variables

3. export variables to calling shell in a shell-script

4. Shell Variables: Shell prompt OK, script, NO.

5. help for newbie: way to get the value of an awk variable in a shell script

6. Passing a variable from a Perl script to a shell script

7. Passing a variable between shell script and perl script

8. export variables to calling shell in a shell-script

9. help with variable in shell script

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software