Solved

arrays in ksh

Posted on 2006-06-15
5
2,353 Views
Last Modified: 2013-12-26
How do I stuff an int vanlue in an array and how do I stuff a string value in an array in ksh ??

0
Comment
Question by:Shweta_Singh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 

Author Comment

by:Shweta_Singh
ID: 16915502
NOTE : the values should be stuffed one by one using a loop and not on a whole seperated by commas.
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 16916610
Something like this should help you

for (( x=1 ; x <= 10; x++;)
do
   array[$x] = $x;
done

array[3] =string;

echo ${array[3]};
0
 

Author Comment

by:Shweta_Singh
ID: 16943206
Okay,
This is where I have reached uptil yet .

All you need to know is that I made an array and that I need to access it's variables which i'm unable to .
Pls help.


#!/usr/bin/ksh
#CREATE AN ARRAY TO STORE OWNERS TO COMPARE
set -A owners `ls -lR "${1}" 2>/dev/null | sed 1d | awk '{print $3}' | sort | uniq`

#LOOP OVER THE ARRAY TO GET THE OWNERS ONE BY ONE TO COMPARE
i=0
while [ $i -lt ${#owners[*]} ]
do
        `ls -lsR "${1}" | awk '/$owners[$i]/ {disk_usage += $6} END {print $owners[$i], " : ", 1*disk_usage, " MB"}'`

        ((i=i+1))
done
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 16944220
> ..  and that I need to access it's variables which i'm unable to
var="${arr_name[$i]}"

as I look at your awk, I guess that the variables you use in awk should be those from your (k)shell, then you need to write that like:
   ls -lsR "${1}" | awk '/'$owners[$i]'/ {disk_usage += $6} END {print '$owners[$i]', " : ", 1*disk_usage, " MB"}'
0
 

Author Comment

by:Shweta_Singh
ID: 16953477
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 95
Shell script to login to remote m/c and execute commands 10 78
has22 challenge 11 107
modThree challenge 4 105
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question