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
Solved

arrays in ksh

Posted on 2006-06-15
5
2,352 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
has22 challenge 11 104
twoTwo  challenge 35 107
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 336
Is there a simple front-end menu system. 9 102
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

789 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