Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

arrays in ksh

Posted on 2006-06-15
5
Medium Priority
?
2,357 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 2000 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

Featured Post

Industry Leaders: 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

730 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