Solved

arrays in ksh

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

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

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. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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