Solved

arrays in ksh

Posted on 2006-06-15
5
2,348 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> ..  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
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to determine file rename from EventLog ? 2 36
sum28 challenge 31 95
twoTwo  challenge 35 86
tripleUp challenge 7 65
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now